/**
  * Register the service provider
  *
  * @return  void
  */
 public function register()
 {
     $this->app['arguments'] = function ($app) {
         global $argv;
         // Register namespace for App commands and component commands
         // @FIXME: neither of these work yet...
         Arguments::registerNamespace('\\App\\Commands');
         Arguments::registerNamespace('\\Components\\{$1}\\Cli\\Commands');
         return new Arguments($argv);
     };
 }
Exemple #2
0
 /**
  * Method to call another console command
  *
  * @param   string  $class      The command to call
  * @param   string  $task       The command task to call
  * @param   object  $arguments  The command arguments
  * @param   object  $output     The command output
  * @return  void
  */
 public function call($class, $task, Arguments $arguments, Output $output)
 {
     // Namespace class
     $class = Arguments::routeCommand($class);
     // Say no to infinite nesting!
     $backtrace = debug_backtrace();
     $previous = $backtrace[1];
     $prevClass = $previous['class'];
     $prevTask = $previous['function'];
     if ($prevClass == $class && $prevTask == $task) {
         $output->error('You\'ve attempted to enter an infinite loop. We\'ve stopped you. You\'re welcome.');
     }
     // If task is help, set the output to our output class with extra methods for rendering help doc
     if ($task == 'help') {
         $output = $output->getHelpOutput();
     }
     $command = new $class($output, $arguments);
     $command->{$task}();
 }
 /**
  * Tests to make sure we can parse options
  *
  * @return  void
  **/
 public function testParseOptions()
 {
     $args = ['muse', 'repository', 'update', '-a', '--b', '--c=foo', '--d=1', '--d=2', '-ef', '-g=bar', '-h=1', '-h=2', '--i-j'];
     $arguments = new Arguments($args);
     $arguments->parse();
     $this->assertTrue($arguments->getOpt('a'), 'Failed to detect parameter "a" as true');
     $this->assertTrue($arguments->getOpt('b'), 'Failed to detect parameter "b" as true');
     $this->assertEquals('foo', $arguments->getOpt('c'), 'Failed to get proper option value for "c"');
     $this->assertEquals(['1', '2'], $arguments->getOpt('d'), 'Failed to get proper option value for "d"');
     $this->assertTrue($arguments->getOpt('e'), 'Failed to detect parameter "e" as true');
     $this->assertTrue($arguments->getOpt('f'), 'Failed to detect parameter "f" as true');
     $this->assertEquals('bar', $arguments->getOpt('g'), 'Failed to get proper option value for "g"');
     $this->assertEquals(['1', '2'], $arguments->getOpt('h'), 'Failed to get proper option value for "h"');
     $this->assertTrue($arguments->getOpt('i-j'), 'Failed to detect parameter "i-j" as true');
     $arguments->setOpt('i', 'foobar');
     $this->assertEquals('foobar', $arguments->getOpt('i'), 'Failed to get proper option value for "i"');
     $arguments->deleteOpt('i');
     $this->assertFalse($arguments->getOpt('i'), 'Failed to properly delete option "i"');
     $this->assertEquals(['a' => true, 'b' => true, 'c' => 'foo', 'd' => ['1', '2'], 'e' => true, 'f' => true, 'g' => 'bar', 'h' => ['1', '2'], 'i-j' => true], $arguments->getOpts(), 'Failed to properly fetch all options');
 }