Create the command template.

@depends handle
@param  string $command
@return boolean
967239
private function makeTemplate($command)
    {
        $file = __DIR__ . "/../templates/command.php.dist";

        try {
            if (!file_exists($file)) throw new \Exception("{$file} file is not exist.", 1);

            $template = strtr(file_get_contents($file), [
                '{{namespace}}' => get_app_namespace(),
                '{{command}}' => $command,
                '{{command_name}}' => strtolower($command)
            ]);

            if (!file_exists(app_path("Commands")))
            {
                mkdir(app_path("Commands"), 0755, true);
            }

            $file_path = app_path("Commands/{$command}.php");

            $file = fopen($file_path, "w");
            fwrite($file, $template);
            fclose($file);

            return file_exists($file_path);

        } catch (Exception $e) {
            $output->writeln($e->getMessage());
        }

        return false;
    }
769013
public static function parseAndRunCommand($command)
    {
        try {
            list($class, $method, $args) = TaskManager::parseCommand($command);
            if (!class_exists($class)) {
                TaskLoader::loadController($class);
            }

            $obj = new $class();
            if (!method_exists($obj, $method)) {
                throw new TaskManagerException('method ' . $method . ' not found in class ' . $class);
            }

            return call_user_func_array(array($obj, $method), $args);
        } catch (\Exception $e) {
            echo 'Caught an exception: ' . get_class($e) . ': ' . PHP_EOL . $e->getMessage() . PHP_EOL;
            return false;
        }
    }
557704
public static function writeHelpCommand($command = "") {
		
		/*
		
		The command help follows this format:
		
		Build Command Options
		
		Usage:
		  php core/console --build [--patternsonly|-p] [--nocache|-n] [--enablecss|-c]
		
		Available options:
		  --patternsonly (-p)    Build only the patterns. Does NOT clean public/.
		  --nocache      (-n)    Set the cacheBuster value to 0.
		  --enablecss    (-c)    Generate CSS for each pattern. Resource intensive.
		  --help         (-h)    Display this help message.
		
		Help:
		 The build command builds an entire site a single time. It compiles the patterns and moves content from source/ into public/
		
		 Samples:
		
		   To run and generate the CSS for each pattern:
		     php core/console --build -c
		
		   To build only the patterns and not move other files from source/ to public/
		     php core/console --build -p
		
		   To turn off the cacheBuster
		     php core/console --build -n
		*/
		
		// if given an empty command or the command doesn't exist in the lists give the generic help
		if (empty($command)) {
			self::writeHelp();
			return;
		}
		
		$commandLong       = self::$commands[$command]["commandLong"];
		$commandLongUC     = ucfirst($commandLong);
		$commandHelp       = self::$commands[$command]["commandHelp"];
		$commandExtra      = isset(self::$commands[$command]["commandExtra"]) ? self::$commands[$command]["commandExtra"] : "";
		$commandOptions    = self::$commands[$command]["commandOptions"];
		$commandExamples   = self::$commands[$command]["commandExamples"];
		$commandShort      = self::$commands[$command]["commandShort"];
		$commandShortInc   = ($commandShort != "") ? "|-".$commandShort : "";
		
		// write out the option list and get the longest item
		$optionList = "";
		$lengthLong = 0;
		foreach ($commandOptions as $option => $attributes) {
			$optionShort = (!empty($attributes["optionShort"][0]) && (($attributes["optionShort"][0] != "z") || ($attributes["optionShort"] != ""))) ? "|-".$attributes["optionShort"] : "";
			$optionExtra = (!empty($attributes["optionExtra"])) ? " ".$attributes["optionExtra"] : "";
			$optionList .= "[--".$attributes["optionLong"].$optionShort.$optionExtra."] ";
			$lengthLong = ($attributes["optionLongLength"] > $lengthLong) ? $attributes["optionLongLength"] : $lengthLong;
		}
		
		$commandExampleList = "";
		if (count($commandExamples) > 0) {
			foreach ($commandExamples as $example => $attributes) {
				$commandExampleList .= $attributes["exampleExtra"]." ";
			}
		}
		
		// write out the generic usage info
		self::writeLine("");
		self::writeLine("<h1>".$commandLongUC." Command Options</h1>",true,true);
		self::writeLine("<h2>Usage</h2>:",true,true);
		self::writeLine("  php ".self::$self." --".$commandLong.$commandShortInc." ".$optionList,true,true);
		
		// write out the available options
		if (count($commandOptions) > 0) {
			self::writeLine("<h2>Available options</h2>:",true,true);
			foreach ($commandOptions as $option => $attributes) {
				$optionShort = (!empty($attributes["optionShort"]) && (($attributes["optionShort"][0] != "z") || ($attributes["optionShort"] != ""))) ? "(-".$attributes["optionShort"].")" : "    ";
				$spacer = self::getSpacer($lengthLong,$attributes["optionLongLength"]);
				self::writeLine("  --".$attributes["optionLong"].$spacer.$optionShort."    <desc>".$attributes["optionDesc"]."</desc>",true);
			}
			self::writeLine("");
		}
		
		self::writeLine("<h2>Help</h2>:",true,true);
		self::writeLine("  ".$commandHelp,true,true);
		
		// write out the samples
		if ((count($commandOptions) > 0) || (count($commandExamples) > 0)) {
			self::writeLine("<h2>Samples</h2>:",true,true);
		}
		
		if (count($commandExamples) > 0) {
			foreach ($commandExamples as $example => $attributes) {
				self::writeLine(" ".$attributes["exampleSample"],true,true);
				self::writeLine("   <desc>php ".self::$self." --".$commandLong." ".$attributes["exampleExtra"]."</desc>",true,true);
			}
		}
		
		if (count($commandOptions) > 0) {
			foreach ($commandOptions as $option => $attributes) {
				self::writeLine(" ".$attributes["optionSample"],true,true);
				self::writeLine("   <desc>php ".self::$self." --".$commandLong." --".$attributes["optionLong"]." ".$attributes["optionExtra"]."</desc>",true,true);
			}
		}
		
	}
350215
protected function setCommand($command)
    {
        $this->command = $command;

        if (!is_null($this->loader)) {
            $this->loader->setCommand($this->command);
        }
    }
1015783
public function hasCommandHandler($command)
    {
        $class = get_class($command);

        if (isset($this->handlers[$class])) {
            return true;
        }

        $callback = $this->mapper;

        if (!$callback || method_exists($command, 'handle')) {
            return false;
        }

        $this->handlers[$class] = $callback($command);

        return true;
    }
1026212
protected function _commandEnable($command)
    {
        $entity = $this->getController()->getItem();

        $label = AnTranslator::_('COM-TODOS-ACTION-'.strtoupper($entity->enabled ? 'disable' : 'enable'));

        $action = ($entity->enabled) ? 'disable' : 'enable';

        $command->append(array('label' => $label));

        if ($command->ajax) {
            $command
            ->href($entity->getURL().'&layout=list')
            ->setAttribute('data-action', $action);
        } else {
            $command
            ->href($entity->getURL().'&action='.$action)
            ->setAttribute('data-trigger', 'PostLink');
        }
    }
1199305
protected function registerMakeRuleCommand($command)
     {
         $this->app->singleton($command, function ($app) {
             return new Generators\Commands\RuleMakeCommand($app);
         });
     }
1209845
public function addCommand(Command $command)
    {
        if (is_string($command)) {
            $command = new $command;
        }
        $map = (new CommandMapping($this->parser))->map($command);

        CommandBag::add($map->name, [
            'object' => $command,
            'map' => $map
        ]);

        return $this;
    }
574401
protected function shell($command)
    {
        $process = new Process($command, $this->getBasePath());

        $process->run();

        if (!$process->isSuccessful()) {
            return '';
        }

        return $this->cleanOutput($process->getOutput());
    }
507074
public function toCommandHandler($command)
    {
        $commandClass = get_class($command);
        $handler = substr_replace($commandClass, 'CommandHandler', strrpos($commandClass, 'Command'));

        if ( ! class_exists($handler))
        {
            $message = "Command handler [$handler] does not exist.";

            throw new HandlerNotRegisteredException($message);
        }

        return $handler;
    }
1295064
public function command($command)
    {
        if (! $command instanceof Command) {
            $command = $this[$command];
        }

        $this['console']->add($command);
    }
1356319
public function exec($command)
    {
        // Check for prohibited commands
        foreach ($this->prohibitedCommands as $prohibitedCommand) {
            if (strpos(trim($command), $prohibitedCommand) !== false) {
                throw new \Exception('The shell command ' . $command . ' is prohibited');
            }
        }
        return exec($command);
    }
781732
protected function validateCommand($command) {
        if ( ! is_string($command) && ! is_object($command)) {
            throw new InvalidCommandException(s(
                'Command must be either a class name or an instance, "%s" given.',
                get_type($command)
            ));
        }

        if (is_string($command) && ! class_exists($command)) {
            throw new InvalidCommandException(s(
                'Command "%s" does not exist.',
                $command
            ));
        }

        if ( ! method_exists($command, 'setup') || ! method_exists($command, 'run')) {
            throw new InvalidCommandException(s(
                'Command "%s" must implement methods "setup" and "run".',
                get_type($command)
            ));
        }
    }
1191884
protected function runCommand($command)
    {
        $method = 'image' . ucfirst(strtolower($command['command']));
        if (!method_exists($this, $method)) {
            return false;
        }
        call_user_func_array([$this, $method], $command['params']);
        
        return true;
    }
81631
protected function doAction(Command $command)
    {
        if ($command->name() === '__default__') {
            return $this->notFound();
        }

        // Let the command collect more data (if missing or needs confirmation)
        $command->interact($this->io());

        if (!$command->action() && !\method_exists($command, 'execute')) {
            return;
        }

        $params = [];
        $values = $command->values();
        // We prioritize action to be in line with commander.js!
        $action = $command->action() ?? [$command, 'execute'];

        foreach ($this->getActionParameters($action) as $param) {
            $params[] = $values[$param->getName()] ?? null;
        }

        return $action(...$params);
    }
1020056
public function execute($command) {
    /** @var \Robo\Common\ProcessExecutor $process_executor */
    $process_executor = Robo::process(new Process($command));
    return $process_executor->dir($this->getConfigValue('repo.root'))
      ->printOutput(FALSE)
      ->printMetadata(FALSE)
      ->interactive(FALSE);
  }
836621
protected function registerMakeControllerCommand($command)
    {
        $this->app->singleton($command, function ($app) {
            return new Generators\Commands\ControllerMakeCommand($app);
        });
    }