PHPackages                             vivait/symfony-console-promptable-options - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. vivait/symfony-console-promptable-options

AbandonedArchivedLibrary[CLI &amp; Console](/categories/cli)

vivait/symfony-console-promptable-options
=========================================

Allows you to specify options to be asked for via questions using the Symfony console component.

0.2(9y ago)17.1kMITPHPPHP &gt;=5.5.9

Since Feb 23Pushed 9y agoCompare

[ Source](https://github.com/vivait/symfony-console-promptable-options)[ Packagist](https://packagist.org/packages/vivait/symfony-console-promptable-options)[ RSS](/packages/vivait-symfony-console-promptable-options/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (5)Versions (3)Used By (0)

Promptable Options for Symfony Console
======================================

[](#promptable-options-for-symfony-console)

[![Build Status](https://camo.githubusercontent.com/0b2a8e6643f9a071a2464bf1e30921091e53ccf778101e87173d32c5a1d84c32/68747470733a2f2f7472617669732d63692e6f72672f7669766169742f73796d666f6e792d636f6e736f6c652d70726f6d707461626c652d6f7074696f6e732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/vivait/symfony-console-promptable-options)

Compatibility / Requirements
----------------------------

[](#compatibility--requirements)

- PHP 5.5.9 and above
- symfony/console ^2.8|^3.0

Installation
------------

[](#installation)

`composer require vivait/symfony-console-promptable-options`

Usage
-----

[](#usage)

Configure the promptable options in the `configure()` method of your command.

You can call the `$this->addPrompt(string $optionName, array $configuration = [])` fluently with the other options to add a prompt for a single option.

Alternatively, call `$this->addPrompts(array $options = [])` fluently with the other options to add prompts for multiple options at the same time by providing a key value array of option names and their desired configurations. This does not over-write any previously added prompts, it adds them on to the options. Here's an example of adding multiple prompts:

```
    protected function configure()
    {
        $this
            ->setName('promptable:test')
            ->addPrompts(
                [
                    'name', // No configuration provided - uses defaults
                    'age' => ['type' => 'int', 'required' => true]
                ]
            );
    }
```

Once configured, access options using `$this->getConsoleOptionInput(string $optionName)`.

The table below shows how it acts in various situations:

**Option marked as promptable****Option not promptable****Option supplied via** `--optionName=value`The value of `--optionName=value` will be returnedThe value of `--optionName=value` will be returned**Option not supplied via** `--optionName=value`The option will be asked for via an interactive question`null` will be returned#### Non-interactive commands:

[](#non-interactive-commands)

If you run a command that has promptable options **that are not supplied via** `--optionName=value` then an `\Exception` will be thrown with the message: `"Cannot prompt for optionName, command is running in non-interactive mode"`

#### Example command:

[](#example-command)

```
