Last active
December 16, 2015 12:29
-
-
Save igorw/5435074 to your computer and use it in GitHub Desktop.
Using symfony/console's ArgvInput standalone.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Console\Input\ArgvInput; | |
use Symfony\Component\Console\Input\InputDefinition; | |
use Symfony\Component\Console\Input\InputArgument; | |
use Symfony\Component\Console\Input\InputOption; | |
$input = new ArgvInput($argv, new InputDefinition([ | |
new InputArgument('sql', InputArgument::REQUIRED), | |
new InputOption('update', 'u', InputOption::VALUE_NONE), | |
])); | |
$update = $input->getOption('update'); | |
$sql = $input->getArgument('sql'); | |
// do fun stuff ... |
Or docopt :
<?php
$doc = <<<DOC
Usage:
import/sql [-u | --update] sql
import/sql (-h | --help)
import/sql --version
Options:
-h --help Show this screen.
--version Show version.
-u --update Fun stuff.
DOC;
require('path/to/src/docopt.php');
$args = Docopt\docopt($doc, array('version'=>'import SQL 2.0'));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You call the script by running: