<commit_before><?php
/**
 *
 *  @author     <NAME> <<EMAIL>>
 *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
 *  @package    Ethna
 *  @version    $Id$
 */

/**
 *  Ethna Command
 *
 *  @author     <NAME> <<EMAIL>>
 *  @access     public
 *  @package    Ethna
 */
namespace Ethnam\Generator;
use \Ethna_Controller;
use \Ethna_Util;
use \Ethna;
use \Ethna_Plugin_Subcommand_Base;

class Command
{
    private $version = <<<EOD
Ethnam %s (using PHP %s)
Copyright (c) 2004-%s, @DQNEO and Ethna commiters

EOD;

    /**#@-*/

    // {{{ constructor
    /**
     *  Ethna_Command constructor
     *
     *  @access public
     */
    public function __construct()
    {
    }
    // }}}

    /**
     * コマンドを実行する
     */
    public function run()
    {

        // fetch arguments
        $opt = new Getopt();
        $arg_list = $opt->readPHPArgv();
        if (Ethna::isError($arg_list)) {
            echo $arg_list->getMessage()."\n";
            exit(2);
        }
        array_shift($arg_list);  // remove "command.php"

        //  はじめの引数に - が含まれていればそれを分離する
        //  含まれていた場合、それは -v|--version でなければならない
        list($my_arg_list, $arg_list) = $this->separateArgList($arg_list);
        $r = $opt->getopt($my_arg_list, "v", array("version"));
        if (Ethna::isError($r)) {
            $subCommand = 'help';
        } else {
            // ad-hoc:(
            foreach ($r[0] as $opt) {
                if ($opt[0] == "v" || $opt[0] == "--version") {
                    printf($this->version, ETHNA_VERSION, PHP_VERSION, date('Y'));
                    exit(2);
                }
            }
        }

        if (count($arg_list) == 0) {
            $subCommand = 'help';
        } else {
            $subCommand = array_shift($arg_list);
        }

        $subCommandPlugin = $this->getSubcommandPlugin($subCommand);
        if (Ethna::isError($subCommandPlugin)) {
            printf("no such command: %s\n\n", $subCommand);
            $subCommand = 'help';
            $subCommandPlugin = $this->getSubcommandPlugin($subCommand);
            if (Ethna::isError($subCommandPlugin)) {
                exit(1);  //  should not happen.
            }
        }

        $subCommandPlugin->eh = $this;

        // don't know what will happen:)
        $subCommandPlugin->setArgList($arg_list);
        $r = $subCommandPlugin->perform();
        if (Ethna::isError($r)) {
            printf("error occured w/ command [%s]\n  -> %s\n\n", $subCommand, $r->getMessage());
            if ($r->getCode() == 'usage') {
                $subCommandPlugin->usage();
            }
            exit(1);
        }

    }

    // {{{ getHandler
    /**
     *  get handler object
     *
     *  @access public
     */
    public function getSubcommandPlugin($subCommand)
    {
        $name = preg_replace_callback('/\-(.)/', function($matches){
                return strtoupper($matches[1]);
                    }, ucfirst($subCommand));

        $ctl = new Ethna_Controller(GATEWAY_CLI);
        Ethna::clearErrorCallback();
<commit_msg>temporally do not fallback to help when no subcommand found<commit_after><?php
/**
 *
 *  @author     <NAME> <<EMAIL>>
 *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
 *  @package    Ethna
 *  @version    $Id$
 */

/**
 *  Ethna Command
 *
 *  @author     <NAME> <<EMAIL>>
 *  @access     public
 *  @package    Ethna
 */
namespace Ethnam\Generator;
use \Ethna_Controller;
use \Ethna_Util;
use \Ethna;
use \Ethna_Plugin_Subcommand_Base;

class Command
{
    private $version = <<<EOD
Ethnam %s (using PHP %s)
Copyright (c) 2004-%s, @DQNEO and Ethna commiters

EOD;

    /**#@-*/

    // {{{ constructor
    /**
     *  Ethna_Command constructor
     *
     *  @access public
     */
    public function __construct()
    {
    }
    // }}}

    /**
     * コマンドを実行する
     */
    public function run()
    {

        // fetch arguments
        $opt = new Getopt();
        $arg_list = $opt->readPHPArgv();
        if (Ethna::isError($arg_list)) {
            echo $arg_list->getMessage()."\n";
            exit(2);
        }
        array_shift($arg_list);  // remove "command.php"

        //  はじめの引数に - が含まれていればそれを分離する
        //  含まれていた場合、それは -v|--version でなければならない
        list($my_arg_list, $arg_list) = $this->separateArgList($arg_list);
        $r = $opt->getopt($my_arg_list, "v", array("version"));
        if (Ethna::isError($r)) {
            $subCommand = 'help';
        } else {
            // ad-hoc:(
            foreach ($r[0] as $opt) {
                if ($opt[0] == "v" || $opt[0] == "--version") {
                    printf($this->version, ETHNA_VERSION, PHP_VERSION, date('Y'));
                    exit(2);
                }
            }
        }

        if (count($arg_list) == 0) {
            $subCommand = 'help';
        } else {
            $subCommand = array_shift($arg_list);
        }

        $subCommandPlugin = $this->getSubcommandPlugin($subCommand);
        $subCommandPlugin->eh = $this;

        // don't know what will happen:)
        $subCommandPlugin->setArgList($arg_list);
        $r = $subCommandPlugin->perform();
        if (Ethna::isError($r)) {
            printf("error occured w/ command [%s]\n  -> %s\n\n", $subCommand, $r->getMessage());
            if ($r->getCode() == 'usage') {
                $subCommandPlugin->usage();
            }
            exit(1);
        }

    }

    // {{{ getHandler
    /**
     *  get handler object
     *
     *  @access public
     */
    public function getSubcommandPlugin($subCommand)
    {
        $name = preg_replace_callback('/\-(.)/', function($matches){
                return strtoupper($matches[1]);
                    }, ucfirst($subCommand));

        $ctl = new Ethna_Controller(GATEWAY_CLI);
        Ethna::clearErrorCallback();

{'fraction_non_alphanumeric': 0.16054026329287058, 'fraction_numerical': 0.004274234911950761, 'mean_word_length': 1.7896995708154506, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '604728', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1904, 'n_words': 352}