public function getCommandOptions()
 {
     $options = new DefinedSwitches();
     $options->addSwitch('properties', 'specify the build.properties file to use')->setWithShortSwitch('b')->setWithLongSwitch('build.properties')->setWithRequiredArg('<build.properties>', 'the path to the build.properties file to use')->setArgHasDefaultValueOf('build.properties')->setArgValidator(new MustBeValidFile());
     $options->addSwitch('packageXml', 'specify the package.xml file to expand')->setWithShortSwitch('p')->setWithLongSwitch('packageXml')->setwithRequiredArg('<package.xml>', 'the path to the package.xml file to use')->setArgHasDefaultValueOf('.build/package.xml')->setArgValidator(new MustBeValidFile())->setArgValidator(new MustBeWriteable());
     $options->addSwitch('pearConfig', 'specify the PEAR config to register the channels with')->setWithShortSwitch('P')->setWithLongSwitch('pear-config')->setWithRequiredArg('<pear-config>', 'the PEAR config file to use')->setArgHasDefaultValueOf('.tmp/pear-config')->setArgValidator(new MustBeValidFile());
     return $options;
 }
 public function getCommandOptions()
 {
     $options = new DefinedSwitches();
     $options->addSwitch('properties', 'specify the build.properties file to use')->setWithShortSwitch('b')->setWithLongSwitch('build.properties')->setWithRequiredArg('<build.properties>', 'the path to the build.properties file to use')->setArgHasDefaultValueOf('build.properties')->setArgValidator(new MustBeValidFile());
     $options->addSwitch('packageXml', 'specify the package.xml file to expand')->setWithShortSwitch('p')->setWithLongSwitch('packageXml')->setwithRequiredArg('<package.xml>', 'the path to the package.xml file to use')->setArgHasDefaultValueOf('.build/package.xml')->setArgValidator(new MustBeValidFile())->setArgValidator(new MustBeWriteable());
     $options->addSwitch('srcFolder', 'specify the src folder to feed into package.xml')->setWithShortSwitch('s')->setWithLongSwitch('src')->setWithRequiredArg('<folder>', 'the path to the folder where the package source files are')->setArgHasDefaultValueOf('src')->setArgValidator(new MustBeValidPath());
     $options->addSwitch('packageFolder', 'specify the top-level folder of the package')->setWithShortSwitch('P')->setWithLongSwitch('packageFolder')->setWithRequiredArg('<folder>', 'thepath to the top-level folder of the package')->setArgHasDefaultValueOf('.')->setArgValidator(new MustBeValidPath());
     return $options;
 }
Beispiel #3
0
 public static function buildSwitches()
 {
     $switches = new DefinedSwitches();
     // phix -h || phix -?
     $switches->addSwitch('shortHelp', 'display a summary of the command-line structure')->setWithShortSwitch('h')->setWithShortSwitch('?');
     // phix --help || phix --?
     $switches->addSwitch('longHelp', 'display a full list of supported commands')->setWithLongSwitch('help')->setWithLongSwitch('?');
     // phix -v || phix --version
     $switches->addSwitch('version', 'display phix version number')->setWithShortSwitch('v')->setWithLongSwitch('version');
     // phix -d || phix --debug
     $switches->addSwitch('debug', 'enable debugging output')->setWithShortSwitch('d')->setWithLongSwitch('debug');
     // phix -I<path> || phix --include=<path>
     $switches->addSwitch('include', 'add a folder to load commands from')->setLongDesc("phix finds all of its commands by searching PHP's include_path for PHP files in " . "folders called 'PhixCommands'. If you want to phix to look in other folders " . "without having to add them to PHP's include_path, use --include to tell phix " . "to look in these folders." . \PHP_EOL . \PHP_EOL . "phix expects '<path>' to point to a folder that conforms to the PSR0 standard " . "for autoloaders." . \PHP_EOL . \PHP_EOL . "For example, if your command is the class '\\Me\\Tools\\PhixCommands\\ScheduledTask', phix would " . "expect to autoload this class from the 'Me/Tools/PhixCommands/ScheduledTask.php' file." . \PHP_EOL . \PHP_EOL . "If your class lives in the './myApp/lib/Me/Tools/PhixCommands' folder, you would call phix " . "with 'phix --include=./myApp/lib'")->setWithShortSwitch('I')->setWithLongSwitch('include')->setWithRequiredArg('<path>', 'The path to the folder to include')->setArgValidator(new MustBeValidPath())->setSwitchIsRepeatable();
     // all done!
     return $switches;
 }
Beispiel #4
0
 public function getCommandOptions()
 {
     $options = new DefinedSwitches();
     $options->addSwitch('version', 'show the version number')->setWithShortSwitch('v')->setWithLongSwitch('version');
     $options->addSwitch('properties', 'specify the build.properties file to use')->setWithShortSwitch('b')->setWithLongSwitch('build.properties')->setWithRequiredArg('<build.properties>', 'the path to the build.properties file to use')->setArgHasDefaultValueOf('build.properties');
     $options->addSwitch('packageXml', 'specify the package.xml file to expand')->setWithShortSwitch('p')->setWithLongSwitch('packageXml')->setwithRequiredArg('<package.xml>', 'the path to the package.xml file to use')->setArgHasDefaultValueOf('.build/package.xml');
     $options->addSwitch('srcFolder', 'specify the src folder to feed into package.xml')->setWithShortSwitch('s')->setWithLongSwitch('src')->setWithRequiredArg('<folder>', 'the path to the folder where the package source files are')->setArgHasDefaultValueOf('src');
     $options->addSwitch('help', 'displays a summary of how to use this command')->setWithShortSwitch('h')->setWithShortSwitch('?')->setWithLongSwitch('help');
     $options->addSwitch('include', 'adds additional folders to PHP include_path')->setWithShortSwitch('I')->setWithLongSwitch('include')->setWithRequiredArg('<path>', 'path to add to include_path')->setLongDesc("phix finds all of its commands by searching PHP's include_path for PHP files in " . "folders called 'PhixCommands'. If you want to phix to look in other folders " . "without having to add them to PHP's include_path, use --include to tell phix " . "to look in these folders." . \PHP_EOL . \PHP_EOL . "phix expects '<path>' to point to a folder that conforms to the PSR0 standard " . "for autoloaders." . \PHP_EOL . \PHP_EOL . "For example, if your command is the class '\\Me\\Tools\\PhixCommands\\ScheduledTask', phix would " . "expect to autoload this class from the 'Me/Tools/PhixCommands/ScheduledTask.php' file." . \PHP_EOL . \PHP_EOL . "If your class lives in the './myApp/lib/Me/Tools/PhixCommands' folder, you would call phix " . "with 'phix --include=./myApp/lib'");
     return $options;
 }
 public function testDefaultValuesAreAddedIfNoSwitchesPresent()
 {
     // this is a bug I first discovered in Phix, and here
     // is the code necessary to reproduce the faults
     $options = new DefinedSwitches();
     $options->addSwitch('properties', 'specify the build.properties file to use')->setWithShortSwitch('b')->setWithLongSwitch('build.properties')->setWithRequiredArg('<build.properties>', 'the path to the build.properties file to use')->setArgHasDefaultValueOf('build.properties')->setArgValidator(new MustBeValidFile());
     $options->addSwitch('packageXml', 'specify the package.xml file to expand')->setWithShortSwitch('p')->setWithLongSwitch('packageXml')->setwithRequiredArg('<package.xml>', 'the path to the package.xml file to use')->setArgHasDefaultValueOf('.build/package.xml')->setArgValidator(new MustBeValidFile())->setArgValidator(new MustBeWriteable());
     $options->addSwitch('srcFolder', 'specify the src folder to feed into package.xml')->setWithShortSwitch('s')->setWithLongSwitch('src')->setWithRequiredArg('<folder>', 'the path to the folder where the package source files are')->setArgHasDefaultValueOf('src')->setArgValidator(new MustBeValidPath());
     $argv = array('./Phix', 'pear:expand-package-xml');
     $parser = new CommandLineParser();
     list($parsedSwitches, $argsIndex) = $parser->parseSwitches($argv, 2, $options);
     // did it work?
     $this->assertTrue($parsedSwitches instanceof ParsedSwitches);
     // is the argsIndex pointing to the right place?
     $this->assertTrue(is_int($argsIndex));
     $this->assertEquals(2, $argsIndex);
     // are the defaults present?
     $switches = $parsedSwitches->getSwitches();
     $this->assertTrue(is_array($switches));
     $this->assertEquals(3, count($switches));
     $this->assertTrue(isset($switches['properties']));
     $this->assertTrue(isset($switches['packageXml']));
     $this->assertTrue(isset($switches['srcFolder']));
 }
 public function testCanValidateAllSwitchValuesInOneGo()
 {
     // define the options we are expecting
     $expectedOptions = new DefinedSwitches();
     $switch1 = $expectedOptions->addSwitch('fred', 'desc 1')->setWithOptionalArg("<fish>", 'the fish that fred likes most')->setArgValidator(new MustBeString());
     $switch2 = $expectedOptions->addSwitch('harry', 'desc 2')->setWithOptionalArg('<sauce>', 'the sauce that harry likes most')->setArgValidator(new MustBeInteger());
     // add the parsed results
     $ParsedSwitches = new ParsedSwitches();
     $ParsedSwitches->addSwitch($expectedOptions, 'fred', 'trout');
     $ParsedSwitches->addSwitch($expectedOptions, 'harry', 'salmon');
     // now, can we validate or not?
     $results = $ParsedSwitches->validateSwitchValues();
     // what happened?
     $this->assertTrue(is_array($results));
     $this->assertEquals(1, count($results));
 }