diff --git a/spark b/spark index a25d4b954624..c4ad645a366b 100755 --- a/spark +++ b/spark @@ -52,7 +52,13 @@ error_reporting(-1); ini_set('display_errors', '1'); // Show basic information before we do anything else. -$console->showHeader(); +if (is_int($suppress = array_search('--no-header', $_SERVER['argv'], true))) +{ + unset($_SERVER['argv'][$suppress]); // @codeCoverageIgnore + $suppress = true; +} + +$console->showHeader($suppress); // fire off the command in the main framework. $response = $console->run(); diff --git a/system/CLI/Console.php b/system/CLI/Console.php index c998de4f749e..711184fc9372 100644 --- a/system/CLI/Console.php +++ b/system/CLI/Console.php @@ -65,9 +65,16 @@ public function run(bool $useSafeOutput = false) /** * Displays basic information about the Console. + * + * @param boolean $suppress */ - public function showHeader() + public function showHeader(bool $suppress = false) { + if ($suppress) + { + return; + } + CLI::write(sprintf('CodeIgniter v%s Command Line Tool - Server Time: %s UTC%s', CodeIgniter::CI_VERSION, date('Y-m-d H:i:s'), date('P')), 'green'); CLI::newLine(); } diff --git a/tests/system/CLI/ConsoleTest.php b/tests/system/CLI/ConsoleTest.php index 03602388bb5e..465bf0e0f306 100644 --- a/tests/system/CLI/ConsoleTest.php +++ b/tests/system/CLI/ConsoleTest.php @@ -60,6 +60,14 @@ public function testHeader() $this->assertTrue(strpos($result, sprintf('CodeIgniter v%s Command Line Tool', CodeIgniter::CI_VERSION)) > 0); } + public function testNoHeader() + { + $console = new Console($this->app); + $console->showHeader(true); + $result = CITestStreamFilter::$buffer; + $this->assertSame('', $result); + } + public function testRun() { $request = new CLIRequest(config('App')); diff --git a/user_guide_src/source/cli/cli_commands.rst b/user_guide_src/source/cli/cli_commands.rst index db75c0d1c6f8..65e0f89209fc 100644 --- a/user_guide_src/source/cli/cli_commands.rst +++ b/user_guide_src/source/cli/cli_commands.rst @@ -31,6 +31,10 @@ Some commands take additional arguments, which should be provided directly after > php spark db:seed DevUserSeeder +You may always pass ``--no-header`` to suppress the header output, helpful for parsing results:: + + > php spark cache:clear --no-header + For all of the commands CodeIgniter provides, if you do not provide the required arguments, you will be prompted for the information it needs to run correctly::