| @@ 13-47 (lines=35) @@ | ||
| 10 | ||
| 11 | class RunCommand extends AbstractRepositoryCommand |
|
| 12 | { |
|
| 13 | protected function configure() |
|
| 14 | { |
|
| 15 | $help = <<<HELP |
|
| 16 | Please note that the script repo command runs only scripts which are stored |
|
| 17 | in a defined script folder. |
|
| 18 | ||
| 19 | Script folders can defined by config. |
|
| 20 | ||
| 21 | Example: |
|
| 22 | ||
| 23 | script: |
|
| 24 | folders: |
|
| 25 | - /my/script_folder |
|
| 26 | ||
| 27 | ||
| 28 | There are some pre defined script folders: |
|
| 29 | ||
| 30 | - /usr/local/share/n98-magerun/scripts |
|
| 31 | - ~/.n98-magerun/scripts |
|
| 32 | ||
| 33 | If you like to run a standalone script you can also use the "script" command. |
|
| 34 | ||
| 35 | See: n98-magerun.phar script <filename.magerun> |
|
| 36 | ||
| 37 | HELP; |
|
| 38 | ||
| 39 | $this |
|
| 40 | ->setName('script:repo:run') |
|
| 41 | ->addArgument('script', InputArgument::OPTIONAL, 'Name of script in repository') |
|
| 42 | ->addOption('define', 'd', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Defines a variable') |
|
| 43 | ->addOption('stop-on-error', null, InputOption::VALUE_NONE, 'Stops execution of script on error') |
|
| 44 | ->setDescription('Run script from repository') |
|
| 45 | ->setHelp($help); |
|
| 46 | } |
|
| 47 | ||
| 48 | protected function execute(InputInterface $input, OutputInterface $output) |
|
| 49 | { |
|
| 50 | $files = $this->getScripts(); |
|
| @@ 37-110 (lines=74) @@ | ||
| 34 | protected $productMetadata = null; |
|
| 35 | ||
| 36 | ||
| 37 | protected function configure() |
|
| 38 | { |
|
| 39 | $this |
|
| 40 | ->setName('script') |
|
| 41 | ->addArgument('filename', InputArgument::OPTIONAL, 'Script file') |
|
| 42 | ->addOption('define', 'd', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Defines a variable') |
|
| 43 | ->addOption('stop-on-error', null, InputOption::VALUE_NONE, 'Stops execution of script on error') |
|
| 44 | ->setDescription('Runs multiple n98-magerun commands'); |
|
| 45 | ||
| 46 | $help = <<<HELP |
|
| 47 | Example: |
|
| 48 | ||
| 49 | # Set multiple config |
|
| 50 | config:set "web/cookie/cookie_domain" example.com |
|
| 51 | ||
| 52 | # Set with multiline values with "\n" |
|
| 53 | config:set "general/store_information/address" "First line\nSecond line\nThird line" |
|
| 54 | ||
| 55 | # This is a comment |
|
| 56 | cache:flush |
|
| 57 | ||
| 58 | ||
| 59 | Optionally you can work with unix pipes. |
|
| 60 | ||
| 61 | \$ echo "cache:flush" | n98-magerun-dev script |
|
| 62 | ||
| 63 | \$ n98-magerun.phar script < filename |
|
| 64 | ||
| 65 | It is even possible to create executable scripts: |
|
| 66 | ||
| 67 | Create file `test.magerun` and make it executable (`chmod +x test.magerun`): |
|
| 68 | ||
| 69 | #!/usr/bin/env n98-magerun.phar script |
|
| 70 | ||
| 71 | config:set "web/cookie/cookie_domain" example.com |
|
| 72 | cache:flush |
|
| 73 | ||
| 74 | # Run a shell script with "!" as first char |
|
| 75 | ! ls -l |
|
| 76 | ||
| 77 | # Register your own variable (only key = value currently supported) |
|
| 78 | \${my.var}=bar |
|
| 79 | ||
| 80 | # Let magerun ask for variable value - add a question mark |
|
| 81 | \${my.var}=? |
|
| 82 | ||
| 83 | ! echo \${my.var} |
|
| 84 | ||
| 85 | # Use resolved variables from n98-magerun in shell commands |
|
| 86 | ! ls -l \${magento.root}/code/local |
|
| 87 | ||
| 88 | Pre-defined variables: |
|
| 89 | ||
| 90 | * \${magento.root} -> Magento Root-Folder |
|
| 91 | * \${magento.version} -> Magento Version i.e. 1.7.0.2 |
|
| 92 | * \${magento.edition} -> Magento Edition -> Community or Enterprise |
|
| 93 | * \${magerun.version} -> Magerun version i.e. 1.66.0 |
|
| 94 | * \${php.version} -> PHP Version |
|
| 95 | * \${script.file} -> Current script file path |
|
| 96 | * \${script.dir} -> Current script file dir |
|
| 97 | ||
| 98 | Variables can be passed to a script with "--define (-d)" option. |
|
| 99 | ||
| 100 | Example: |
|
| 101 | ||
| 102 | $ n98-magerun.phar script -d foo=bar filename |
|
| 103 | ||
| 104 | # This will register the variable \${foo} with value bar. |
|
| 105 | ||
| 106 | It's possible to define multiple values by passing more than one option. |
|
| 107 | HELP; |
|
| 108 | $this->setHelp($help); |
|
| 109 | } |
|
| 110 | ||
| 111 | /** |
|
| 112 | * @return bool |
|
| 113 | */ |
|