Skip to content

Commit

Permalink
Add show-workflows command
Browse files Browse the repository at this point in the history
The command aims to show all available personal and common workflows
for the repository.

Adding of the command encourages to change the layout of the main help
message. The updated help groups the commands based on their purposes
rather than by the type of objects they interact with.

Also, for the optimization of further development, the `workflows`
plugin is introduced. It serves all workflows-specific common logic.
  • Loading branch information
extsoft committed Apr 5, 2020
1 parent 821bc43 commit c28762e
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 29 deletions.
1 change: 1 addition & 0 deletions completions/_git-elegant
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ _git-elegant (){
'show-commands:prints available Elegant Git commands'
'show-release-notes:prints a release log between two references'
'show-work:shows a state of current work in progress'
'show-workflows:shows configured workflows in the repository'
'start-work:creates a new branch'
)

Expand Down
52 changes: 40 additions & 12 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,36 @@ usage: git elegant [-h | --help | help | --version | version]

There are commands used in various situations such as

act with a repository
enable Elegnat Git services
acquire-git Configures a Git installation.
acquire-repository Configures current repository.
clone-repository Clones a repository and configures it.
init-repository Initializes a new repository and configures it.
acquire-repository Configures current repository.

serve a repository
prune-repository Removes useless local branches.

manage a personal work
enhance contribution rules
show-workflows Shows configured workflows in the repository.

make day-to-day contributions
start-work Creates a new branch.
save-work Commits current modifications.
amend-work Amends some changes to the most recent commit.
show-work Shows a state of current work in progress.
polish-work Reapplies branch commits interactively.
deliver-work Publishes current branch to a remote repository.

operate a flow of work management
interact with others
deliver-work Publishes current branch to a remote repository.
obtain-work Checkouts a remote branch matching by a name.
accept-work Incorporates a branch on top of the `master`.

release new versions
show-release-notes Prints a release log between two references.
manage contributions
accept-work Incorporates a branch on top of the `master`.
release-work Releases available work as a new annotated tag.
show-release-notes Prints a release log between two references.

and others
show-commands Prints available Elegant Git commands.
acquire-git Configures a Git installation.


Please visit https://elegant-git.bees-hive.org to find out more.
Expand Down Expand Up @@ -312,7 +317,7 @@ Displays all available Elegant Git commands. This is useful for completion
functions as well as for other cases when you need iteration over the available
commands.

Approximate commands flow is
Approximate command's output is
```bash
==>> git elegant show-commands
start-work
Expand All @@ -338,10 +343,9 @@ There are two options for a `layout`:
hosting is unknown, the default layout is used. Now only GitHub is supported
(an HTML output).

Approximate commands flow is
Approximate command's output is
```bash
==>> git elegant show-release-notes
# produces output like this
Release notes
- Add `show-release-notes` command
- Add `release-work` command
Expand All @@ -365,6 +369,30 @@ git status --short
git stash list
```

# `show-workflows`

```bash
usage: git elegant show-workflows
```

Shows all personal and common workflows files that are available in the
repository.

Personal workflows are located in `.git/.workflows` directory and common ones
are in \'.workflows` relatively to the repository root directory.

Approximate command's output is
```bash
==>> git elegant show-workflows
.git/.workflows/accept-work-after
.workflows/amend-work-ahead
.workflows/amend-work-after
.workflows/release-work-after
.workflows/save-work-ahead
.workflows/save-work-after
....
```

# `start-work`

```bash
Expand Down
31 changes: 17 additions & 14 deletions libexec/git-elegant
Original file line number Diff line number Diff line change
Expand Up @@ -71,31 +71,36 @@ usage: git elegant [-h | --help | help | --version | version]
There are commands used in various situations such as
act with a repository
enable Elegnat Git services
$(--print-command-in-usage acquire-git)
$(--print-command-in-usage acquire-repository)
$(--print-command-in-usage clone-repository)
$(--print-command-in-usage init-repository)
$(--print-command-in-usage acquire-repository)
serve a repository
$(--print-command-in-usage prune-repository)
manage a personal work
enhance contribution rules
$(--print-command-in-usage show-workflows)
make day-to-day contributions
$(--print-command-in-usage start-work)
$(--print-command-in-usage save-work)
$(--print-command-in-usage amend-work)
$(--print-command-in-usage show-work)
$(--print-command-in-usage polish-work)
$(--print-command-in-usage deliver-work)
operate a flow of work management
interact with others
$(--print-command-in-usage deliver-work)
$(--print-command-in-usage obtain-work)
$(--print-command-in-usage accept-work)
release new versions
$(--print-command-in-usage show-release-notes)
manage contributions
$(--print-command-in-usage accept-work)
$(--print-command-in-usage release-work)
$(--print-command-in-usage show-release-notes)
and others
$(--print-command-in-usage show-commands)
$(--print-command-in-usage acquire-git)
Please visit ${__site} to find out more.
Expand All @@ -113,11 +118,8 @@ MESSAGE
--run-workflow(){
local type=${1}
local command=${2}
if [[ ! "init-repository clone-repository" =~ ${command} ]]; then
local prefix=$(git rev-parse --show-cdup 2>/dev/null)
fi
--run-file "${prefix}.git/.workflows/${command}-${type}"
--run-file "${prefix}.workflows/${command}-${type}"
--run-file "$(personal-workflows-file ${command} ${type})"
--run-file "$(common-workflows-file ${command} ${type})"
}

--load-command(){
Expand Down Expand Up @@ -148,6 +150,7 @@ MESSAGE
default "$@"
;;
*)
source ${BINS}/plugins/workflows
--run-workflow ahead ${COMMAND}
default "$@"
--run-workflow after ${COMMAND}
Expand Down
2 changes: 1 addition & 1 deletion libexec/git-elegant-show-commands
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Displays all available Elegant Git commands. This is useful for completion
functions as well as for other cases when you need iteration over the available
commands.
Approximate commands flow is
Approximate command's output is
\`\`\`bash
==>> git elegant show-commands
start-work
Expand Down
3 changes: 1 addition & 2 deletions libexec/git-elegant-show-release-notes
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ There are two options for a \`layout\`:
hosting is unknown, the default layout is used. Now only GitHub is supported
(an HTML output).
Approximate commands flow is
Approximate command's output is
\`\`\`bash
==>> git elegant show-release-notes
# produces output like this
Release notes
- Add \`show-release-notes\` command
- Add \`release-work\` command
Expand Down
50 changes: 50 additions & 0 deletions libexec/git-elegant-show-workflows
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env bash

command-purpose() {
cat <<MESSAGE
Shows configured workflows in the repository.
MESSAGE
}

command-synopsis() {
cat <<MESSAGE
usage: git elegant show-workflows
MESSAGE
}

command-description() {
cat<<MESSAGE
Shows all personal and common workflows files that are available in the
repository.
Personal workflows are located in \`.git/.workflows\` directory and common ones
are in \'.workflows\` relatively to the repository root directory.
Approximate command's output is
\`\`\`bash
==>> git elegant show-workflows
.git/.workflows/accept-work-after
.workflows/amend-work-ahead
.workflows/amend-work-after
.workflows/release-work-after
.workflows/save-work-ahead
.workflows/save-work-after
....
\`\`\`
MESSAGE
}

--list() {
if test -e "${1}" ; then
echo "${1}"
fi
}

default() {
for command in $(git elegant show-commands); do
--list $(personal-workflows-file ${command} ahead)
--list $(personal-workflows-file ${command} after)
--list $(common-workflows-file ${command} ahead)
--list $(common-workflows-file ${command} after)
done
}
27 changes: 27 additions & 0 deletions libexec/plugins/workflows
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

--prefix(){
if [[ ! "init-repository clone-repository" =~ ${1} ]]; then
git rev-parse --show-cdup 2>/dev/null
fi
}

personal-workflows() {
# usage: personal-workflows <command>
echo "$(--prefix ${1}).git/.workflows"
}

common-workflows() {
# usage: common-workflows <command>
echo "$(--prefix ${1}).workflows"
}

personal-workflows-file() {
# usage: personal-workflows-file <comand> <type>
echo "$(personal-workflows ${1})/${1}-${2}"
}

common-workflows-file() {
# usage: common-workflows-file <comand> <type>
echo "$(common-workflows ${1})/${1}-${2}"
}
1 change: 1 addition & 0 deletions tests/git-elegant-show-commands.bats
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ teardown() {
"show-release-notes"
"release-work"
"polish-work"
"show-workflows"
)
check git-elegant show-commands
[[ ${#lines[@]} -eq ${#COMMANDS[@]} ]]
Expand Down
27 changes: 27 additions & 0 deletions tests/git-elegant-show-workflows.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bats

load addons-common
load addons-repo

setup() {
repo-new
}

teardown(){
repo-clean
}

@test "'show-workflows': displays all available workflow files" {
repo "mkdir -p .workflows .git/.workflows"
repo "echo echo ahead git > .git/.workflows/start-work-ahead"
repo "echo echo ahead no > .workflows/start-work-ahead"
repo "echo echo after git > .git/.workflows/start-work-after"
repo "echo echo after no > .workflows/start-work-after"
repo "ls -lah .git/.workflows/* .workflows/*"
check git-elegant show-workflows
[[ ${status} -eq 0 ]]
[[ ${lines[0]} =~ ".git/.workflows/start-work-ahead" ]]
[[ ${lines[1]} =~ ".git/.workflows/start-work-after" ]]
[[ ${lines[2]} =~ ".workflows/start-work-ahead" ]]
[[ ${lines[3]} =~ ".workflows/start-work-after" ]]
}

0 comments on commit c28762e

Please sign in to comment.