Ejemplo n.º 1
0
 public function t1estThemData()
 {
     $args1 = pw\Args\Args::factory()->opt("a")->aka("aaa")->long("abc")->req()->desc("abcabc abcabc\nabcabc")->end()->opt("len")->long("length")->default("10")->end()->opt("f")->bool()->default(false)->desc("Flag\nwhatever")->end()->opt()->array()->require()->desc("data files")->obey(function ($vals) {
         return sizeof($vals) >= 2;
     }, "Require at least two data files")->end();
     $args2 = pw\Args\Args::factory();
     $args3 = pw\Args\Args::factory();
     $args4 = pw\Args\Args::factory();
     $args5 = pw\Args\Args::factory();
     $ret = [[$args1, "--help", "\nUsage:\n  argsTest.php [options]\n\nOptions:\n  -a,   -aaa                               -> abcabc abcabc\n    ,   --abc                                 abcabc\n                                              Required.\n  -len, --length                           -> Default: \"10\"\n  -f                                       -> Flag\n                                              whatever\n                                              Default: false\n  -                                        -> data files\n                                              Required.\n  -h,   --help                             -> Print help for the program.\n\n"], [clone $args1, "-a", "Error: Option -a is required.                                              |" . "\n\nUsage:\n  argsTest.php [options]\n\nOptions:\n  -a,   -aaa                               -> abcabc abcabc\n    ,   --abc                                 abcabc\n                                              Required.\n  -len, --length                           -> Default: \"10\"\n  -f                                       -> Flag\n                                              whatever\n                                              Default: false\n  -                                        -> data files\n                                              Required.\n  -h,   --help                             -> Print help for the program.\n\n"], [clone $args1, "-a 1 -h", "\nUsage:\n  argsTest.php [options]\n\nOptions:\n  -a,   -aaa                               -> abcabc abcabc\n    ,   --abc                                 abcabc\n                                              Required.\n  -len, --length                           -> Default: \"10\"\n  -f                                       -> Flag\n                                              whatever\n                                              Default: false\n  -                                        -> data files\n                                              Required.\n  -h,   --help                             -> Print help for the program.\n\n"]];
     $return = [];
     foreach ($ret as $i => $r) {
         $return[] = [$i, $r[0], $r[1], $r[2]];
     }
     return $return;
 }
Ejemplo n.º 2
0
 /**
  * @ignore
  */
 protected function addHelpOpts()
 {
     if (in_array($this->name, $this->args->_getHelpCmds())) {
         return;
     }
     parent::addHelpOpts();
 }
Ejemplo n.º 3
0
 public function testOptionDone()
 {
     $args = Args::factory();
     $option = $args->option("a");
     $option->callback(function ($opt) {
         $value = $opt->getValue();
         $opt->setValue("{$value}{$value}");
     });
     $option->done(["-a", "abc"]);
     $this->assertEquals("abcabc", $option->getValue());
     $args = Args::factory();
     $option = $args->option("a");
     $option->must(function ($opt) {
         return $opt->getValue() == "111";
     }, "Error happens");
     $option->done(["-a", "abc"]);
     $this->assertRegexp("/Error happens/", implode("", $this->invokeProperty($args, "errors")));
     $option = $args->option();
 }