src/Charcoal/App/Script/AbstractScript.php
protected function input($name)
    {
        $cli = $this->climate();
        $arg = $this->argument($name);

        if ($arg) {
            $type = (isset($arg['inputType']) ? $arg['inputType'] : 'input');

            if (isset($arg['prompt'])) {
                $label = $arg['prompt'];
            } elseif (isset($arg['description'])) {
                $label = $arg['description'];
            } else {
                $label = $name;
            }

            if (isset($arg['choices'])) {
                $arg['options'] = $arg['choices'];
                $arg['acceptValue'] = $arg['choices'];
            }

            $accept = true;
        } else {
            $type   = 'input';
            $label  = $name;
            $accept = false;
        }

        $prompt = 'prompt';
        switch ($type) {
            case 'checkboxes':
            case 'radio':
                if (!isset($arg['options'])) {
                    throw new RuntimeException(
                        sprintf('The [%s] argument has no options.', $name)
                    );
                }

                $accept = false;
                $input  = $cli->{$type}($label, $arg['options'], $this->climateReader);
                break;

            case 'confirm':
                $prompt = 'confirmed';
                $input  = $cli->confirm($label, $this->climateReader);
                break;

            case 'password':
                $input = $cli->password($label, $this->climateReader);
                $input->multiLine();
                break;

            case 'multiline':
                $input = $cli->input($label, $this->climateReader);
                $input->multiLine();
                break;

            default:
                $input = $cli->input($label, $this->climateReader);
                break;
        }

        if ($accept) {
            if (isset($arg['acceptValue'])) {
                if (is_array($arg['acceptValue']) || is_callable($arg['acceptValue'])) {
                    $input->accept($arg['acceptValue']);
                }
            }
        }

        return $input->{$prompt}();
    }
protected function input($name)
    {
        $cli = $this->climate();
        $arg = $this->argument($name);

        if ($arg) {
            $type = (isset($arg['inputType']) ? $arg['inputType'] : 'input');

            if (isset($arg['prompt'])) {
                $label = $arg['prompt'];
            } elseif (isset($arg['description'])) {
                $label = $arg['description'];
            } else {
                $label = $name;
            }

            if (isset($arg['choices'])) {
                $arg['options'] = $arg['choices'];
                $arg['acceptValue'] = $arg['choices'];
            }

            $accept = true;
        } else {
            $type   = 'input';
            $label  = $name;
            $accept = false;
        }

        $prompt = 'prompt';
        switch ($type) {
            case 'checkboxes':
            case 'radio':
                if (!isset($arg['options'])) {
                    throw new RuntimeException(
                        sprintf('The [%s] argument has no options.', $name)
                    );
                }

                $accept = false;
                $input  = $cli->{$type}($label, $arg['options'], $this->climateReader);
                break;

            case 'confirm':
                $prompt = 'confirmed';
                $input  = $cli->confirm($label, $this->climateReader);
                break;

            case 'password':
                $input = $cli->password($label, $this->climateReader);
                $input->multiLine();
                break;

            case 'multiline':
                $input = $cli->input($label, $this->climateReader);
                $input->multiLine();
                break;

            default:
                $input = $cli->input($label, $this->climateReader);
                break;
        }

        if ($accept) {
            if (isset($arg['acceptValue'])) {
                if (is_array($arg['acceptValue']) || is_callable($arg['acceptValue'])) {
                    $input->accept($arg['acceptValue']);
                }
            }
        }

        return $input->{$prompt}();
    }
protected function input ( $ name ) { $ cli = $ this -> climate ( ) ; $ arg = $ this -> argument ( $ name ) ; if ( $ arg ) { $ type = ( isset ( $ arg [ 'inputType' ] ) ? $ arg [ 'inputType' ] : 'input' ) ; if ( isset ( $ arg [ 'prompt' ] ) ) { $ label = $ arg [ 'prompt' ] ; } elseif ( isset ( $ arg [ 'description' ] ) ) { $ label = $ arg [ 'description' ] ; } else { $ label = $ name ; } if ( isset ( $ arg [ 'choices' ] ) ) { $ arg [ 'options' ] = $ arg [ 'choices' ] ; $ arg [ 'acceptValue' ] = $ arg [ 'choices' ] ; } $ accept = true ; } else { $ type = 'input' ; $ label = $ name ; $ accept = false ; } $ prompt = 'prompt' ; switch ( $ type ) { case 'checkboxes' : case 'radio' : if ( ! isset ( $ arg [ 'options' ] ) ) { throw new RuntimeException ( sprintf ( 'The [%s] argument has no options.' , $ name ) ) ; } $ accept = false ; $ input = $ cli -> { $ type } ( $ label , $ arg [ 'options' ] , $ this -> climateReader ) ; break ; case 'confirm' : $ prompt = 'confirmed' ; $ input = $ cli -> confirm ( $ label , $ this -> climateReader ) ; break ; case 'password' : $ input = $ cli -> password ( $ label , $ this -> climateReader ) ; $ input -> multiLine ( ) ; break ; case 'multiline' : $ input = $ cli -> input ( $ label , $ this -> climateReader ) ; $ input -> multiLine ( ) ; break ; default : $ input = $ cli -> input ( $ label , $ this -> climateReader ) ; break ; } if ( $ accept ) { if ( isset ( $ arg [ 'acceptValue' ] ) ) { if ( is_array ( $ arg [ 'acceptValue' ] ) || is_callable ( $ arg [ 'acceptValue' ] ) ) { $ input -> accept ( $ arg [ 'acceptValue' ] ) ; } } } return $ input -> { $ prompt } ( ) ; }
Request a value from the user for the given argument.

@param  string $name An argument identifier.
@throws RuntimeException If a radio or checkbox prompt has no options.
@return mixed Returns the prompt value.
Request a value from the user for the given argument .