/** * Load the config. * * @param string $argv The command line string. */ public function loadConfig($argv = []) { $args = new Args(); $args->argument('config', ['default' => 'kahlan-config.php']); $args->argument('help', ['type' => 'boolean']); $args->argument('version', ['type' => 'boolean']); $args->parse($argv); $run = function ($args) { if (file_exists($args->get('config'))) { require $args->get('config'); } }; $run($args); $this->_args->parse($argv, false); if ($args->get('help')) { return $this->_help(); } if ($args->get('version')) { return $this->_version(); } }
$actual = $args->parse(['command']); expect($args->get('argument1'))->toEqual('config_value'); $actual = $args->parse(['command', '--argument1']); expect($args->get('argument1'))->toEqual('config_value'); $actual = $args->parse(['command', '--argument1="some_value"']); expect($args->get('argument1'))->toEqual('config_value'); }); it("formats value according to value function", function () { $args = new Args(['argument1' => ['type' => 'string', 'default' => 'default_value', 'value' => function ($value, $name, $args) { if (!$value) { return 'empty_value'; } return 'non_empty_value'; }]]); $actual = $args->parse(['command']); expect($args->get('argument1'))->toEqual('default_value'); $actual = $args->parse(['command', '--argument1']); expect($args->get('argument1'))->toEqual('empty_value'); $actual = $args->parse(['command', '--argument1="some_value"']); expect($args->get('argument1'))->toEqual('non_empty_value'); }); }); describe("->exists()", function () { it("returns `true` if the argument exists", function () { $args = new Args(); $actual = $args->parse(['command', '--argument1', '--argument2=true', '--argument3=false', '--argument4=0']); expect($args->exists('argument1'))->toBe(true); expect($args->exists('argument2'))->toBe(true); expect($args->exists('argument3'))->toBe(true); expect($args->exists('argument4'))->toBe(true); expect($args->exists('argument5'))->toBe(false);