<commit_before><?php

namespace org\octris\core\octsh\app {
    use \org\octris\core\app as app;
    use \org\octris\core\validate as validate;
    
    /**
     * Help system for the shell.
     *
     * @octdoc      c:app/help
     * @copyright   copyright (c) 2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class help extends \org\octris\core\octsh\libs\plugin
    /**/
    {
        /**
         * The entry points to which the current page should allow requests to have to be defined with this
         * property.
         *
         * @octdoc  v:help/$next_page
         * @var     array
         */
        protected $next_pages = array();
        /**/

        /**
         * Command to display help for.
         *
         * @octdoc  v:help/$command
         * @var     string
         */
        protected $command = '';
        /**/

        /**
         * Constructor.
         *
         * @octdoc  m:page/__construct
         */
        public function __construct()
        /**/
        {
            parent::__construct();
            
            $registry = \org\octris\core\registry::getInstance();

            $this->addValidator('help', $_REQUEST, array(
                'type'              => validate::T_OBJECT,
                'keyrename'         => array('command'),
                'properties'        => array(
                    'command'       => array(
                        'type'      => validate::T_CALLBACK,
                        'options'   => array(
                            'callback'  => function($command) use ($registry) {
                                $errors = array();
                                
                                if (!isset($registry->commands)) {
                                    $errors[] = 'help is not available';
                                } elseif (!isset($registry->commands[$command])) {
                                    $errors[] = "no help available for unknown command '$command'";
                                }

                                return (count($errors) == 0
                                        ? true
                                        : $errors);
                            }
                        )
                    )        
                )
            ));
             
            // 'project'       => array(
            //     'type'      => validate::T_CHAIN,
            //     'chain' => array(
            //         array(
            //             'type'      => validate::T_PROJECT,
            //             'invalid'   => 'Project name is invalid'
            //         ),
            //         array(
            //             'type'      => validate::T_CALLBACK,
            //             'options'   => array(
            //             'callback'  => function($value) {
            //                 print "$value\n";
            //                 return true;
            //             }
            //         )
            //     )
            // )
        }

        /**
         * Prepare page
         *
         * @octdoc  m:help/prepare
         * @param   \org\octris\core\app\page       $last_page      Instance of last called page.
         * @param   string                          $action         Action that led to current page.
         * @return  mixed                                           Returns either page to redirect to or null.
         */
        public function prepare(\org\octris\core\app\page $last_page, $action)
        /**/
        {
            return ($this->validate()
                    ? null
                    : $last_page);
            // $command  = array_shift($parameters);
            // 
            // if (is_scalar($command)) {
            // } elseif (is_array($command)) {
            //     $last_page->addError("usage: 'help' or 'help <command>'");
            // }
            // 
            return (count($last_page->errors) == 0
                    ? null
                    : $last_page);
        }

        /**
         * Implements dialog.
         *
         * @octdoc  m:help/dialog
         * @param   string                          $action         Action that led to current page.
         */
        public function dialog($action)
        /**/
        {
            $registry = \org\octris\core\registry::getInstance();
            
            if ($this->command == '') {
                print "List of all OCTRiS shell commands:\n\n";
                
                foreach ($registry->commands as $command => $class) {
                    printf("    %s\n", $command);
                }
                
                print "\n";
                print "Enter 'help <command>' for more information on a specific command.\n";
            } else {
                printf("Help for command '%s':\n\n", $this->command);
            }
        }
    }
}
<commit_msg>- changed help to work with validator changes<commit_after><?php

namespace org\octris\core\octsh\app {
    use \org\octris\core\app as app;
    use \org\octris\core\validate as validate;
    
    /**
     * Help system for the shell.
     *
     * @octdoc      c:app/help
     * @copyright   copyright (c) 2011 by <NAME>
     * @author      <NAME> <<EMAIL>>
     */
    class help extends \org\octris\core\octsh\libs\plugin
    /**/
    {
        /**
         * The entry points to which the current page should allow requests to have to be defined with this
         * property.
         *
         * @octdoc  v:help/$next_page
         * @var     array
         */
        protected $next_pages = array();
        /**/

        /**
         * Command to display help for.
         *
         * @octdoc  v:help/$command
         * @var     string
         */
        protected $command = '';
        /**/

        /**
         * Constructor.
         *
         * @octdoc  m:page/__construct
         */
        public function __construct()
        /**/
        {
            parent::__construct();
            
            $registry = \org\octris\core\registry::getInstance();

            $this->addValidator('help', $_REQUEST, array(
                'type'              => validate::T_OBJECT,
                'keyrename'         => array('command'),
                'properties'        => array(
                    'command'       => array(
                        'type'      => validate::T_CALLBACK,
                        'callback'  => function($command, $validator) use ($registry) {
                            print "test";
                            
                            if (!($return = isset($registry->commands))) {
                                $validator->addError('help is not available');
                            } elseif (!($return = isset($registry->commands[$command]))) {
                                $validator->addError("no help available for unknown command '$command'");
                            }

                            return $return;
                        }
                    )        
                )
            ));
             
            // 'project'       => array(
            //     'type'      => validate::T_CHAIN,
            //     'chain' => array(
            //         array(
            //             'type'      => validate::T_PROJECT,
            //             'invalid'   => 'Project name is invalid'
            //         ),
            //         array(
            //             'type'      => validate::T_CALLBACK,
            //             'options'   => array(
            //             'callback'  => function($value) {
            //                 print "$value\n";
            //                 return true;
            //             }
            //         )
            //     )
            // )
        }

        /**
         * Prepare page
         *
         * @octdoc  m:help/prepare
         * @param   \org\octris\core\app\page       $last_page      Instance of last called page.
         * @param   string                          $action         Action that led to current page.
         * @return  mixed                                           Returns either page to redirect to or null.
         */
        public function prepare(\org\octris\core\app\page $last_page, $action)
        /**/
        {
            if (($return = $this->applyValidator($action)) !== true) {
                $last_page->addErrors($return);
                
                // return $last_page;
            }

            print_r($_REQUEST);
            die;

        }

        /**
         * Validate parameters.
         *
         * @octdoc  m:help/validate
         * @param   string                          $action         Action that led to current page.
         * @return  
         */
        public function validate()
        /**/
        {
            return true;
        }

        /**
         * Implements dialog.
         *
         * @octdoc  m:help/dialog
         * @param   string                          $action         Action that led to current page.
         */
        public function dialog($action)
        /**/
        {
            $registry = \org\octris\core\registry::getInstance();
            
            if ($this->command == '') {
                print "List of all OCTRiS shell commands:\n\n";
                
                foreach ($registry->commands as $command => $class) {
                    printf("    %s\n", $command);
                }
                
                print "\n";
                print "Enter 'help <command>' for more information on a specific command.\n";
            } else {
                printf("Help for command '%s':\n\n", $this->command);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.11755678330263966, 'fraction_numerical': 0.0010231225700838961, 'mean_word_length': 0.8819792067770504, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2338694', 'n_tokens_mistral': 2382, 'n_tokens_neox': 2315, 'n_words': 521}