From: Christian Weiske Date: Wed, 31 Jan 2018 10:17:42 +0000 (+0100) Subject: Add --dry-run option for getting curl commands X-Git-Tag: v0.7.0~6 X-Git-Url: https://git.cweiske.de/shpub.git/commitdiff_plain/a460539284aca97046cfd0b46d2c6dd832b43c39 Add --dry-run option for getting curl commands --- diff --git a/src/shpub/Cli.php b/src/shpub/Cli.php index 113c149..fcc6070 100644 --- a/src/shpub/Cli.php +++ b/src/shpub/Cli.php @@ -78,6 +78,7 @@ class Cli } } $this->cfg->setDebug($opts['debug']); + $this->cfg->setDryRun($opts['dryrun']); return $res; } catch (\Exception $exc) { @@ -119,6 +120,16 @@ class Cli 'default' => false, ) ); + $optParser->addOption( + 'dryrun', + array( + 'short_name' => '-n', + 'long_name' => '--dry-run', + 'description' => 'Do not send modifying HTTP request(s) to the server', + 'action' => 'StoreTrue', + 'default' => false, + ) + ); Command_Connect::opts($optParser); Command_Server::opts($optParser); diff --git a/src/shpub/Config.php b/src/shpub/Config.php index 2ca7d9a..f3ca543 100644 --- a/src/shpub/Config.php +++ b/src/shpub/Config.php @@ -14,6 +14,8 @@ class Config public $debug = false; + public $dryRun = false; + protected function getConfigFilePath() { if (!isset($_SERVER['HOME'])) { @@ -91,7 +93,7 @@ class Config return $key; } } - + reset($this->hosts); return key($this->hosts); } @@ -121,5 +123,10 @@ class Config { $this->debug = $debug; } + + public function setDryRun($dryRun) + { + $this->dryRun = $dryRun; + } } ?> diff --git a/src/shpub/Request.php b/src/shpub/Request.php index dce163f..4437164 100644 --- a/src/shpub/Request.php +++ b/src/shpub/Request.php @@ -93,6 +93,16 @@ class Request $cp = new CurlPrinter(); $cp->show($this->req, $this->uploadsInfo, $this->dedicatedBody); } + + if ($this->cfg->dryRun && $this->req->getMethod() != 'GET') { + //do not run any modifying queries + //fake a successful response + $res = new \HTTP_Request2_Response('HTTP/1.1 200 OK', false); + $res->parseHeaderLine('Content-type: text/plain'); + $res->appendBody('Fake --dry-run response'); + return $res; + } + $res = $this->req->send(); if (intval($res->getStatus() / 100) != 2) {