<commit_before><?php

/*
 * This file is part of the 'octris' package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace octris {
    /**
     * Main application class.
     *
     * @octdoc      c:libs/main
     * @copyright   copyright (c) 2014 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class main 
    /**/
    {
        /**
         * Octris tool version and version-date.
         *
         * @octdoc  d:main/T_VERSION
         * @type    string
         */
        const T_VERSION = '0.0.1';
        const T_VERSION_DATE = '2014-00-00';
        /**/

        /**
         * Available commands.
         *
         * @octdoc  p:main/$commands
         * @type    array
         */
        protected $commands = array();
        /**/

        /**
         * Constructor.
         *
         * @octdoc  m:main/__construct
         * @param   
         */
        public function __construct()
        /**/
        {
        }

        /**
         * Determine available "commands".
         *
         * @octdoc  m:main/getCommands
         */
        protected function getCommands()
        /**/
        {
            $this->commands = array();
            
            foreach (new \DirectoryIterator(__DIR__ . '/command/') as $file) {
                if (!$file->isDot() && substr(($name = $file->getFilename()), -4) == '.php') {
                    $command = basename($name, '.class.php');
                    
                    $this->commands[$command] = '\\octris\\command\\' . $command;
                }
            }
            
            ksort($this->commands);
        }
    
        /**
         * Run main application.
         *
         * @octdoc  m:main/run
         */
        public function run()
        /**/
        {
            global $argv;
            
            $this->getCommands();
            
            array_shift($argv);
            
            if (!($arg = array_shift($argv))) {
                $this->showUsage();
                exit(1);
            }

            $help = false;

            switch ($arg) {
                case '--help':
                    $this->showUsage();
                    exit(1);
                case '--version':
                    printf("octris %s (%s)\n", self::T_VERSION, self::T_VERSION_DATE);
                    exit(1);
                case 'help':
                    $help = true;
                    $arg  = array_shift($argv);
                    /** FALL THRU **/
                default:
                    if (!(preg_match('/^[a-z]+$/', $arg))) {
                        $this->showUsage();
                        exit(1);
                    } elseif (!file_exists(__DIR__ . '/command/' . $arg . '.class.php')) {
                        printf("octris: '%s' is not a command\n", $arg);
                        exit(1);
                    } else {
                        require_once(__DIR__ . '/command/' . $arg . '.class.php');
                        
                        $class    = "\\octris\\command\\$arg";
                        
                        if ($help) {
                            printf("octris: manual for command '%s'\n\n", $arg);
                            
                            print rtrim($class::getManual(), "\n") . "\n";
                            exit(1);
                        } else {
                            $instance = new $class($argv);
                            exit($instance->run());
                        }
                    }
            }

            exit(0);
        }
    
        /**
         * Show usage information.
         *
         * @octdoc  m:main/showUsage
         */
        public function showUsage()
        /**/
        {
            printf("               __         .__        
  ____   _____/  |________|__| ______
 /  _ \_/ ___\   __\_  __ \  |/  ___/    OCTRiS framework tool
(  <_> )  \___|  |  |  | \/  |\___ \     copyright (c) 2014 by <NAME>
 \____/ \___  >__|  |__|  |__/____  >    http://github.com/octris/octris/
            \/%20s\/

usage: octris --help
usage: octris --version
usage: octris help <command>
usage: octris <command> [ARGUMENTS]

Commands:
", 'v' . self::T_VERSION);

            $size = array_reduce(array_keys($this->commands), function($size, $item) {
                return max($size, strlen($item));
            }, 0);

            foreach ($this->commands as $command => $class) {
                printf("    %-" . $size . "s    %s\n", $command, $class::getDescription());
            }
        }
    
        /**
         * Class Autoloader.
         *
         * @octdoc  m:main/autoload
         * @param   string          $classpath              Path of class to load.
         */
        public static function autoload($classpath)
        /**/
        {
            if (substr($classpath, 0, 6) == 'octris') {
                $file = __DIR__ . '/' . preg_replace('|\\\\|', '/', substr($classpath, 6)) . '.class.php';

                @include_once($file);
            }        
        }
    }

    spl_autoload_register(array('\octris\main', 'autoload'));
}
<commit_msg>help is now implemented as command, too<commit_after><?php

/*
 * This file is part of the 'octris' package.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace octris {
    /**
     * Main application class.
     *
     * @octdoc      c:libs/main
     * @copyright   copyright (c) 2014 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class main 
    /**/
    {
        /**
         * Octris tool version and version-date.
         *
         * @octdoc  d:main/T_VERSION
         * @type    string
         */
        const T_VERSION = '0.0.1';
        const T_VERSION_DATE = '2014-00-00';
        /**/

        /**
         * Available commands.
         *
         * @octdoc  p:main/$commands
         * @type    array
         */
        protected $commands = array();
        /**/

        /**
         * Constructor.
         *
         * @octdoc  m:main/__construct
         * @param   
         */
        public function __construct()
        /**/
        {
        }

        /**
         * Determine available "commands".
         *
         * @octdoc  m:main/getCommands
         */
        protected function getCommands()
        /**/
        {
            $this->commands = array();
            
            foreach (new \DirectoryIterator(__DIR__ . '/command/') as $file) {
                if (!$file->isDot() && substr(($name = $file->getFilename()), -4) == '.php') {
                    $command = basename($name, '.class.php');
                    
                    $this->commands[$command] = '\\octris\\command\\' . $command;
                }
            }
            
            ksort($this->commands);
        }
    
        /**
         * Run main application.
         *
         * @octdoc  m:main/run
         */
        public function run()
        /**/
        {
            global $argv;
            
            $this->getCommands();
            
            array_shift($argv);
            
            if (!($arg = array_shift($argv))) {
                $this->showUsage();
                exit(1);
            }

            switch ($arg) {
                case '--help':
                    $this->showUsage();
                    exit(1);
                case '--version':
                    printf("octris %s (%s)\n", self::T_VERSION, self::T_VERSION_DATE);
                    exit(1);
                default:
                    if (!(preg_match('/^[a-z]+$/', $arg))) {
                        $this->showUsage();
                        exit(1);
                    } elseif (!file_exists(__DIR__ . '/command/' . $arg . '.class.php')) {
                        printf("octris: '%s' is not a command\n", $arg);
                        exit(1);
                    } else {
                        require_once(__DIR__ . '/command/' . $arg . '.class.php');
                        
                        $class    = "\\octris\\command\\$arg";
                        $instance = new $class($argv);
                        
                        exit($instance->run());
                    }
            }

            exit(0);
        }
    
        /**
         * Show usage information.
         *
         * @octdoc  m:main/showUsage
         */
        public function showUsage()
        /**/
        {
            printf("               __         .__        
  ____   _____/  |________|__| ______
 /  _ \_/ ___\   __\_  __ \  |/  ___/    OCTRiS framework tool
(  <_> )  \___|  |  |  | \/  |\___ \     copyright (c) 2014 by <NAME>
 \____/ \___  >__|  |__|  |__/____  >    http://github.com/octris/octris/
            \/%20s\/

usage: octris --help
usage: octris --version
usage: octris help <command>
usage: octris <command> [ARGUMENTS]

Commands:
", 'v' . self::T_VERSION);

            $size = array_reduce(array_keys($this->commands), function($size, $item) {
                return max($size, strlen($item));
            }, 0);

            foreach ($this->commands as $command => $class) {
                printf("    %-" . $size . "s    %s\n", $command, $class::getDescription());
            }
        }
    
        /**
         * Class Autoloader.
         *
         * @octdoc  m:main/autoload
         * @param   string          $classpath              Path of class to load.
         */
        public static function autoload($classpath)
        /**/
        {
            if (substr($classpath, 0, 6) == 'octris') {
                $file = __DIR__ . '/' . preg_replace('|\\\\|', '/', substr($classpath, 6)) . '.class.php';

                @include_once($file);
            }        
        }
    }

    spl_autoload_register(array('\octris\main', 'autoload'));
}

{'fraction_non_alphanumeric': 0.14619766163685421, 'fraction_numerical': 0.00649545318277206, 'mean_word_length': 1.0362156663275686, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '70167', 'n_tokens_mistral': 2866, 'n_tokens_neox': 2728, 'n_words': 542}