From c9cbdc079ca8bdd5c4176074fd6c689f31d685d5 Mon Sep 17 00:00:00 2001 From: Dmytro Serdiuk Date: Mon, 6 Apr 2020 16:34:01 +0300 Subject: [PATCH] Add `polish-workflow` command The command just opens a given workflows file for editing. And completions will provide only available files which improve a user experience. --- completions/_git-elegant | 5 ++++ completions/git-elegant.bash | 5 ++++ docs/commands.md | 16 +++++++++++++ libexec/git-elegant | 1 + libexec/git-elegant-polish-workflow | 36 ++++++++++++++++++++++++++++ tests/git-elegant-show-commands.bats | 1 + 6 files changed, 64 insertions(+) create mode 100644 libexec/git-elegant-polish-workflow diff --git a/completions/_git-elegant b/completions/_git-elegant index 5535c8e..7230e75 100755 --- a/completions/_git-elegant +++ b/completions/_git-elegant @@ -21,6 +21,7 @@ _git-elegant (){ 'make-workflow:makes a new workflow file for the repository' 'obtain-work:checkouts a remote branch matching by a name' 'polish-work:reapplies branch commits interactively' + 'polish-workflow:edits a given workflows file' 'prune-repository:removes useless local branches' 'release-work:releases available work as a new annotated tag' 'save-work:commits current modifications' @@ -67,6 +68,10 @@ __ge_complete_commands () { show-release-notes) __ge_show_release_notes ;; start-work) __ge_start_work ;; make-workflow) __ge_make_workflow ;; + polish-workflow) + local files=($(git elegant show-workflows)) + _arguments '--help' '--no-workflows' '1:file:(${files[@]})' + ;; *) _arguments '--help' '--no-workflows' ;; esac } diff --git a/completions/git-elegant.bash b/completions/git-elegant.bash index 7b93061..c9507fd 100755 --- a/completions/git-elegant.bash +++ b/completions/git-elegant.bash @@ -44,6 +44,11 @@ _git_elegant() { show-release-notes) COMPREPLY=( $(compgen -W "simple smart ${gecops[*]}" -- ${cursor}) ) ;; + polish-workflow) + COMPREPLY=( + $(compgen -W "${opts[*]} $(git elegant show-workflows)" -- ${cursor}) + ) + ;; *) COMPREPLY=( $(compgen -W "${gecops[*]}" -- ${cursor}) ) ;; diff --git a/docs/commands.md b/docs/commands.md index d877f4b..473f978 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -26,6 +26,7 @@ There are commands used in various situations such as enhance contribution rules show-workflows Shows configured workflows in the repository. make-workflow Makes a new workflow file for the repository. + polish-workflow Edits a given workflows file. make day-to-day contributions start-work Creates a new branch. @@ -262,6 +263,21 @@ Approximate commands flow is git rebase --interactive @~5 ``` +# `polish-workflow` + +```bash +usage: git elegant polish-workflow +``` + +Opens a given workflow file in the default text editor. If given file is not +present, the command raises an error. + +Approximate commands flow is +```bash +==>> git elegant polish-workflow .workflows/show-work-ahead +vim .workflows/show-work-ahead +``` + # `prune-repository` ```bash diff --git a/libexec/git-elegant b/libexec/git-elegant index 7f530aa..1cae5b8 100755 --- a/libexec/git-elegant +++ b/libexec/git-elegant @@ -83,6 +83,7 @@ $(--print-command-in-usage prune-repository) enhance contribution rules $(--print-command-in-usage show-workflows) $(--print-command-in-usage make-workflow) +$(--print-command-in-usage polish-workflow) make day-to-day contributions $(--print-command-in-usage start-work) diff --git a/libexec/git-elegant-polish-workflow b/libexec/git-elegant-polish-workflow new file mode 100644 index 0000000..4869a9f --- /dev/null +++ b/libexec/git-elegant-polish-workflow @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +command-purpose() { + cat < +MESSAGE +} + +command-description() { + cat<> git elegant polish-workflow .workflows/show-work-ahead +vim .workflows/show-work-ahead +\`\`\` +MESSAGE +} + +default() { + _error-if-empty "${1}" "Please specify a workflow file name" + if test -e ${file}; then + $(git config core.editor) ${file} + else + error-text "The '${file}' file does not exist." + exit 43 + fi +} diff --git a/tests/git-elegant-show-commands.bats b/tests/git-elegant-show-commands.bats index d46a070..5b393b1 100644 --- a/tests/git-elegant-show-commands.bats +++ b/tests/git-elegant-show-commands.bats @@ -31,6 +31,7 @@ teardown() { "polish-work" "show-workflows" "make-workflow" + "polish-workflow" ) check git-elegant show-commands [[ ${#lines[@]} -eq ${#COMMANDS[@]} ]]