From 133e94f320ceef9414664234795f4f0aaf2a4096 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 17 Feb 2019 11:48:51 +0100 Subject: [PATCH] allow to pass arbitrary options to composer and run git command just in apps (--git-apps) --- install-cli.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/install-cli.php b/install-cli.php index e0e480c238..5792d47d61 100755 --- a/install-cli.php +++ b/install-cli.php @@ -3,13 +3,17 @@ /** * Install / update EGroupware - Command line interface * - * Usage: install-cli.php [-v|--verbose] [--use-prerelease] (master|bugfix|release||) - * install-cli.php --git # runs git with given arguments in all app-dirs - * # e.g. tag -a 17.1.20190214 -m 'tagging release' + * Usage: + * + * - install-cli.php [-v|--verbose] [--use-prerelease] [(master|bugfix|release||)] + * you can use composer install arguments like: --ignore-platform-reqs --no-dev + * + * - install-cli.php --git(-apps) + * runs git with given arguments (in main- and) all app-dirs, e.g. tag -a 17.1.20190214 -m 'tagging release' * * EGroupware main directory should be either git cloned: * - * git clone -b https://github.com/EGroupware/egroupware [] + * git clone [-b ] https://github.com/EGroupware/egroupware [] * * or created via composer create-project * @@ -47,6 +51,7 @@ error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT); // parse arguments $verbose = $use_prerelease = $run_git = false; +$composer_args = []; $argv = $_SERVER['argv']; $cmd = array_shift($argv); @@ -73,12 +78,15 @@ foreach($argv as $n => $arg) usage(); case '--git': - $run_git = true; + case '--git-apps': + $run_git = $arg; unset($argv[$n]); break 2; // no further argument processing, as they are for git - default: - usage("Unknown argument '$arg'!"); + default: // pass unknown arguments to composer install + $composer_args[] = $arg; + unset($argv[$n]); + break; } } } @@ -159,7 +167,7 @@ if (!file_exists(__DIR__.'/.git') || !is_dir(__DIR__.'/.git')) // should we only run a git command if ($run_git) { - exit (run_git($argv)); + exit (run_git($argv, $run_git === '--git')); } if (!exec($git.' branch --no-color', $output, $ret) || $ret) @@ -245,7 +253,7 @@ foreach(scandir(__DIR__) as $dir) } // update composer managed dependencies -$cmd = $composer.' install'; +$cmd = $composer.' install '.implode(' '.$composer_args); if ($verbose) echo "$cmd\n"; system($cmd); @@ -261,14 +269,15 @@ if ($npm && $grunt) } /** - * Run git command with given arguments in install-dir and all app-dirs + * Run git command with given arguments all app-dirs and (optional) install-dir * * cd and git command is echoed to stderr * * @param array $argv + * @param booelan $main_too =true true: run in main-dir too, false: only app-dirs * @return int exit-code of last git command, breaks on first non-zero exit-code */ -function run_git(array $argv) +function run_git(array $argv, $main_too=true) { global $git; @@ -277,7 +286,8 @@ function run_git(array $argv) $ret = 0; foreach(scandir(__DIR__) as $dir) { - if ($dir !== '..' && file_exists(__DIR__.'/'.$dir.'/.git')) + if (!($dir === '..' || $dir === '.' && !$main_too || + !file_exists(__DIR__.'/'.$dir.'/.git'))) { $cmd = ($dir !== '.' ? "cd $dir; " : '').$git_cmd;