From 1b1074047329da1f30832651eba4ca432a3f1147 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Tue, 3 Feb 2015 13:44:42 +0100 Subject: [PATCH 1/2] Added --list to run-script command, closes #3671 --- src/Composer/Command/RunScriptCommand.php | 25 ++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/RunScriptCommand.php b/src/Composer/Command/RunScriptCommand.php index f01a5febe..91a9b2abe 100644 --- a/src/Composer/Command/RunScriptCommand.php +++ b/src/Composer/Command/RunScriptCommand.php @@ -54,10 +54,11 @@ class RunScriptCommand extends Command ->setName('run-script') ->setDescription('Run the scripts defined in composer.json.') ->setDefinition(array( - new InputArgument('script', InputArgument::REQUIRED, 'Script name to run.'), + new InputArgument('script', InputArgument::OPTIONAL, 'Script name to run.'), new InputArgument('args', InputArgument::IS_ARRAY | InputArgument::OPTIONAL, ''), new InputOption('dev', null, InputOption::VALUE_NONE, 'Sets the dev mode.'), new InputOption('no-dev', null, InputOption::VALUE_NONE, 'Disables the dev mode.'), + new InputOption('list', 'l', InputOption::VALUE_NONE, 'List scripts.'), )) ->setHelp(<<run-script command runs scripts defined in composer.json: @@ -70,6 +71,12 @@ EOT protected function execute(InputInterface $input, OutputInterface $output) { + if ($input->getOption('list')) { + return $this->listScripts($input, $output); + } elseif (!$input->getArgument('script')) { + throw new \RunTimeException('Missing required argument "script"'); + } + $script = $input->getArgument('script'); if (!in_array($script, $this->commandEvents) && !in_array($script, $this->scriptEvents)) { if (defined('Composer\Script\ScriptEvents::'.str_replace('-', '_', strtoupper($script)))) { @@ -97,4 +104,20 @@ EOT return $composer->getEventDispatcher()->dispatchScript($script, $input->getOption('dev') || !$input->getOption('no-dev'), $args); } + + protected function listScripts(InputInterface $input, OutputInterface $output) + { + $scripts = $this->getComposer()->getPackage()->getScripts(); + + if (!count($scripts)) { + return 0; + } + + $output->writeln('scripts:'); + foreach ($scripts as $name => $script) { + $output->writeln(' ' . $name); + } + + return 0; + } } From 1575f19ef274f96f479a2dba0b6c4cbe8f088f34 Mon Sep 17 00:00:00 2001 From: Rob Bast Date: Tue, 3 Feb 2015 15:26:02 +0100 Subject: [PATCH 2/2] Updated documentation --- doc/03-cli.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/03-cli.md b/doc/03-cli.md index 40478ee9b..dd1121c80 100644 --- a/doc/03-cli.md +++ b/doc/03-cli.md @@ -507,8 +507,13 @@ Lists the name, version and license of every package installed. Use ## run-script +### Options + +* **--no-dev:** Disable dev mode +* **--list:** List user defined scripts + To run [scripts](articles/scripts.md) manually you can use this command, -just give it the script name and optionally --no-dev to disable the dev mode. +just give it the script name and optionally any required arguments. ## diagnose