diff options
| author | Teddy Wing | 2018-02-28 23:54:48 +0100 |
|---|---|---|
| committer | Teddy Wing | 2018-02-28 23:54:48 +0100 |
| commit | 9cff7d9059ba9834aebdb6806f65f408a705d934 (patch) | |
| tree | de9600c841df180ed1a0c6089a7c600dba3db639 | |
| parent | a66d6ed85250eaadaab7edcf976ab3f6d7a74fd7 (diff) | |
| download | harvester-9cff7d9059ba9834aebdb6806f65f408a705d934.tar.bz2 | |
harvester: Add `--update-module` flag
This new flag provides an interface to update the current sprint (or
"module" or "task") of a project. Running a command like:
$ harvester -p proj --update-module
will open `pick` with the list of tasks for that module. The task chosen
from the given list becomes the new sprint associated with the project
alias. This makes it much easier to update sprints.
Move error handling into the more general `exit_with_error` function to
exit with a default error message prefix. The error message is also now
printed to STDERR, which is more standard, and wasn't the case before.
| -rwxr-xr-x | harvester | 44 |
1 files changed, 41 insertions, 3 deletions
@@ -30,18 +30,25 @@ Flags: -d, --date=DATE Date when work was done (e.g. 2017-01-31). -m, --description=DESCRIPTION Description of work. --list-modules List project sprints with IDs. + --update-module Change the sprint of the given project. -v, --version Show application version. __EOF__ } -function error_flag () { - local flag="$1" +function exit_with_error () { + local message="$1" - echo "harvester: error: required flag $flag not provided, try --help" + echo "harvester: error: $message" 1>&2 exit 1 } +function error_flag () { + local flag="$1" + + exit_with_error "required flag $flag not provided, try --help" +} + function hcl_log () { local project="$1" local time="$2" @@ -68,6 +75,32 @@ function list_modules () { hcl tasks | grep "^${project_id}" } +function update_module () { + local project="$1" + + if [ -z "$project" ]; then + error_flag '--project' + fi + + if ! command -v pick > /dev/null; then + exit_with_error '--update-module requires `pick(1)` (https://github.com/calleerlandsson/pick)' + fi + + module_id=$(list_modules "$project" | + pick | + cut -d ' ' -f 1) + + if [ -z "$module_id" ]; then + exit_with_error 'bad module ID' + fi + + project_id="${module_id% *}" + task_id="${module_id#* }" + + hcl unalias "$project" + hcl alias "$project" "$project_id" "$task_id" +} + function main () { local project='' local time='7' @@ -129,6 +162,11 @@ function main () { return 0 ;; + --update-module) + update_module "$project" + + return + ;; --help) print_usage |
