Recommend this page to a friend! |
Download |
Info | Example | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 53 | All time: 10,641 This week: 68 |
Version | License | PHP version | Categories | |||
strargs 1.0.0 | MIT/X Consortium ... | 5 | PHP 5, Text processing, Console |
> Advanced CLI Command Parser
<?php
$strargs = new \IsaEken\Strargs\Strargs('command "my name is" "isa eken" --details="{\"age\": 19, \"gender\": \"Male\"}" --friends[]=\"Nur\" -vvv');
$strargs->getArgument(0); // "my name is"
$strargs->getArgument(1); // "isa eken"
$strargs->getOption('details'); // (object) ["age" => 19, "gender" => "Male"]
$strargs->getOption('friends'); // ['Nur']
$strargs->getVerbose(); // "debug"
You can install using composer.
composer require isaeken/strargs
$strargs = new \IsaEken\Strargs\Strargs;
$strargs->setCommand('/usr/bin/php');
$strargs->setArgument(0, '/var/www/html');
$strargs->setOption('action', 'serve');
$strargs->setOption('post', $_POST);
$strargs->addFlag('local');
$strargs->setVerbose(\IsaEken\Strargs\Enums\VerboseLevel::VERY_VERBOSE);
$strargs->encode(); // /usr/bin/php "/var/www/html" --action="serve" --local -vv
$strargs = new \IsaEken\Strargs\Strargs('command arg1 arg2 --json1="{\"key\":\"value\"}" --json2="[\"asd\"]" --arr1[]="item1" --arr1[]="item2" --arr1[]=10 --arr2[]="item" --opt=1 --opt2="value" -a -b -c --ab --tr --try');
// Call this method first.
$strargs->decode();
$strargs->getArgument(0); // arg1
$strargs->getArgument(1); // arg2
$strargs->getOption('json1'); // (object) ['key' => 'value']
$strargs->getOption('arr1'); // ['item1', 'item2', 10]
$strargs->getVerbose(); // normal
$strargs->hasFlag('try'); // true
$strargs->hasFlag('c'); // true
$strargs->hasFlag('d'); // false
The MIT License (MIT). Please see License File for more information.
Files (20) |
File | Role | Description | ||
---|---|---|---|---|
src (2 files, 4 directories) | ||||
tests (2 files) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE.md | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Example | Example script |
Files (20) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Contracts (5 files) | ||||
Enums (1 file) | ||||
Exceptions (1 file) | ||||
Traits (5 files) | ||||
Helpers.php | Class | Class source | ||
Strargs.php | Class | Class source |
Files (20) | / | src | / | Contracts |
File | Role | Description |
---|---|---|
HasArguments.php | Class | Class source |
HasCommand.php | Class | Class source |
HasFlags.php | Class | Class source |
HasOptions.php | Class | Class source |
HasVerbose.php | Class | Class source |
Files (20) | / | src | / | Traits |
File | Role | Description |
---|---|---|
HasArguments.php | Class | Class source |
HasCommand.php | Class | Class source |
HasFlags.php | Class | Class source |
HasOptions.php | Class | Class source |
HasVerbose.php | Class | Class source |
Files (20) | / | tests |
File | Role | Description |
---|---|---|
HelperTest.php | Class | Class source |
StringTest.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.