diff --git a/docs/artifacts.md b/docs/artifacts.md index c68c1c9d..1ad3edc8 100644 --- a/docs/artifacts.md +++ b/docs/artifacts.md @@ -16,10 +16,10 @@ All artifact configuration should be in your project's base properties file, `.t ## Runtime flags -* `push` - Value should be `y` or `n`. When this flag is provided, it will bypass the "Push artifact changes?" prompt. +* `artifact.result` - Value should be `push`, `keep`, or `discard`. When this flag is provided, it will bypass the "Push artifact changes?" prompt. ``` -$> phing artifact -Dpush=y +$> phing artifact -Dartifact.result=keep ``` ## Examples diff --git a/src/TheBuild/SelectOneTask.php b/src/TheBuild/SelectOneTask.php new file mode 100644 index 00000000..2b65d71a --- /dev/null +++ b/src/TheBuild/SelectOneTask.php @@ -0,0 +1,129 @@ + + * + * + * @endcode + * + * @copyright 2018 Palantir.net, Inc. + */ + +namespace TheBuild; + +use BuildException; +use Project; + + +class SelectOneTask extends \Task { + + /** + * @var string + * Required. List of values to select among. + */ + protected $list = ''; + + /** + * @var string + * String to split the list by. + */ + protected $delimiter = ','; + + /** + * @var string + * Required. Property to populate with the selected value. + */ + protected $propertyName = ''; + + /** + * @var string + * Message to display to the user when more than one key is available. + */ + protected $message = 'Select one:'; + + + /** + * Select menu. + */ + public function main() { + $this->validate(); + + $project = $this->getProject(); + + if ($existing_value = $this->project->getProperty($this->propertyName)) { + $this->log("Using {$this->propertyName} = '{$existing_value}' (existing value)", Project::MSG_INFO); + return; + } + + $keys = array_map('trim', explode($this->delimiter, $this->list)); + + if (count($keys) > 1) { + // Prompt for input. + $request = new MenuInputRequest($this->message); + $request->setOptions($keys); + + $this->project->getInputHandler()->handleInput($request); + + $value = $request->getInput(); + } + elseif (count($keys) == 1) { + $value = current($keys); + $this->log("Using {$this->propertyName} = '{$value}' (one value found)", Project::MSG_INFO); + } + + if ($value) { + $project->setNewProperty($this->propertyName, $value); + } + } + + + /** + * Verify that the required attributes are set. + */ + public function validate() { + foreach (['list', 'propertyName'] as $attribute) { + if (empty($this->$attribute)) { + throw new BuildException("$attribute attribute is required.", $this->location); + } + } + } + + /** + * @param string $value + */ + public function setList($value) { + $this->list = $value; + } + + /** + * @param string $value + */ + public function setDelimiter($value) { + $this->delimiter = $value; + } + + /** + * @param string $value + */ + public function setPropertyName($value) { + $this->propertyName = $value; + } + + /** + * @param string $value + */ + public function setMessage($value) { + $this->message = $value; + } + +} diff --git a/tasks/artifact.xml b/tasks/artifact.xml index 24bb4c6c..b9b9b3b9 100644 --- a/tasks/artifact.xml +++ b/tasks/artifact.xml @@ -63,9 +63,7 @@ - - - + @@ -276,38 +274,66 @@ - + + + - - - - + - + + + - + - Pushing changes. - + + + Artifact changes are in the temporary branch '${artifact.git.temporary_branch}' + + - - - - - - - + + + + + + + + + + + + + Pushing changes. + + + + + + + + + + + + + + + + + - - + + diff --git a/tasks/the-build.xml b/tasks/the-build.xml index 0dd92d46..38dbb629 100644 --- a/tasks/the-build.xml +++ b/tasks/the-build.xml @@ -27,6 +27,9 @@ + + + @@ -92,15 +95,15 @@ - - + + - - + + - - + +