Skip to content

Commit c28762e

Browse files
committed
Add show-workflows command
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.
1 parent 821bc43 commit c28762e

File tree

9 files changed

+165
-29
lines changed

9 files changed

+165
-29
lines changed

completions/_git-elegant

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ _git-elegant (){
2525
'show-commands:prints available Elegant Git commands'
2626
'show-release-notes:prints a release log between two references'
2727
'show-work:shows a state of current work in progress'
28+
'show-workflows:shows configured workflows in the repository'
2829
'start-work:creates a new branch'
2930
)
3031

docs/commands.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,36 @@ usage: git elegant [-h | --help | help | --version | version]
1414

1515
There are commands used in various situations such as
1616

17-
act with a repository
17+
enable Elegnat Git services
18+
acquire-git Configures a Git installation.
19+
acquire-repository Configures current repository.
1820
clone-repository Clones a repository and configures it.
1921
init-repository Initializes a new repository and configures it.
20-
acquire-repository Configures current repository.
22+
23+
serve a repository
2124
prune-repository Removes useless local branches.
2225

23-
manage a personal work
26+
enhance contribution rules
27+
show-workflows Shows configured workflows in the repository.
28+
29+
make day-to-day contributions
2430
start-work Creates a new branch.
2531
save-work Commits current modifications.
2632
amend-work Amends some changes to the most recent commit.
2733
show-work Shows a state of current work in progress.
2834
polish-work Reapplies branch commits interactively.
29-
deliver-work Publishes current branch to a remote repository.
3035

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

35-
release new versions
36-
show-release-notes Prints a release log between two references.
40+
manage contributions
41+
accept-work Incorporates a branch on top of the `master`.
3742
release-work Releases available work as a new annotated tag.
43+
show-release-notes Prints a release log between two references.
3844

3945
and others
4046
show-commands Prints available Elegant Git commands.
41-
acquire-git Configures a Git installation.
4247

4348

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

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

341-
Approximate commands flow is
346+
Approximate command's output is
342347
```bash
343348
==>> git elegant show-release-notes
344-
# produces output like this
345349
Release notes
346350
- Add `show-release-notes` command
347351
- Add `release-work` command
@@ -365,6 +369,30 @@ git status --short
365369
git stash list
366370
```
367371

372+
# `show-workflows`
373+
374+
```bash
375+
usage: git elegant show-workflows
376+
```
377+
378+
Shows all personal and common workflows files that are available in the
379+
repository.
380+
381+
Personal workflows are located in `.git/.workflows` directory and common ones
382+
are in \'.workflows` relatively to the repository root directory.
383+
384+
Approximate command's output is
385+
```bash
386+
==>> git elegant show-workflows
387+
.git/.workflows/accept-work-after
388+
.workflows/amend-work-ahead
389+
.workflows/amend-work-after
390+
.workflows/release-work-after
391+
.workflows/save-work-ahead
392+
.workflows/save-work-after
393+
....
394+
```
395+
368396
# `start-work`
369397

370398
```bash

libexec/git-elegant

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,31 +71,36 @@ usage: git elegant [-h | --help | help | --version | version]
7171
7272
There are commands used in various situations such as
7373
74-
act with a repository
74+
enable Elegnat Git services
75+
$(--print-command-in-usage acquire-git)
76+
$(--print-command-in-usage acquire-repository)
7577
$(--print-command-in-usage clone-repository)
7678
$(--print-command-in-usage init-repository)
77-
$(--print-command-in-usage acquire-repository)
79+
80+
serve a repository
7881
$(--print-command-in-usage prune-repository)
7982
80-
manage a personal work
83+
enhance contribution rules
84+
$(--print-command-in-usage show-workflows)
85+
86+
make day-to-day contributions
8187
$(--print-command-in-usage start-work)
8288
$(--print-command-in-usage save-work)
8389
$(--print-command-in-usage amend-work)
8490
$(--print-command-in-usage show-work)
8591
$(--print-command-in-usage polish-work)
86-
$(--print-command-in-usage deliver-work)
8792
88-
operate a flow of work management
93+
interact with others
94+
$(--print-command-in-usage deliver-work)
8995
$(--print-command-in-usage obtain-work)
90-
$(--print-command-in-usage accept-work)
9196
92-
release new versions
93-
$(--print-command-in-usage show-release-notes)
97+
manage contributions
98+
$(--print-command-in-usage accept-work)
9499
$(--print-command-in-usage release-work)
100+
$(--print-command-in-usage show-release-notes)
95101
96102
and others
97103
$(--print-command-in-usage show-commands)
98-
$(--print-command-in-usage acquire-git)
99104
100105
101106
Please visit ${__site} to find out more.
@@ -113,11 +118,8 @@ MESSAGE
113118
--run-workflow(){
114119
local type=${1}
115120
local command=${2}
116-
if [[ ! "init-repository clone-repository" =~ ${command} ]]; then
117-
local prefix=$(git rev-parse --show-cdup 2>/dev/null)
118-
fi
119-
--run-file "${prefix}.git/.workflows/${command}-${type}"
120-
--run-file "${prefix}.workflows/${command}-${type}"
121+
--run-file "$(personal-workflows-file ${command} ${type})"
122+
--run-file "$(common-workflows-file ${command} ${type})"
121123
}
122124

123125
--load-command(){
@@ -148,6 +150,7 @@ MESSAGE
148150
default "$@"
149151
;;
150152
*)
153+
source ${BINS}/plugins/workflows
151154
--run-workflow ahead ${COMMAND}
152155
default "$@"
153156
--run-workflow after ${COMMAND}

libexec/git-elegant-show-commands

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Displays all available Elegant Git commands. This is useful for completion
1919
functions as well as for other cases when you need iteration over the available
2020
commands.
2121
22-
Approximate commands flow is
22+
Approximate command's output is
2323
\`\`\`bash
2424
==>> git elegant show-commands
2525
start-work

libexec/git-elegant-show-release-notes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ There are two options for a \`layout\`:
2626
hosting is unknown, the default layout is used. Now only GitHub is supported
2727
(an HTML output).
2828
29-
Approximate commands flow is
29+
Approximate command's output is
3030
\`\`\`bash
3131
==>> git elegant show-release-notes
32-
# produces output like this
3332
Release notes
3433
- Add \`show-release-notes\` command
3534
- Add \`release-work\` command

libexec/git-elegant-show-workflows

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
3+
command-purpose() {
4+
cat <<MESSAGE
5+
Shows configured workflows in the repository.
6+
MESSAGE
7+
}
8+
9+
command-synopsis() {
10+
cat <<MESSAGE
11+
usage: git elegant show-workflows
12+
MESSAGE
13+
}
14+
15+
command-description() {
16+
cat<<MESSAGE
17+
Shows all personal and common workflows files that are available in the
18+
repository.
19+
20+
Personal workflows are located in \`.git/.workflows\` directory and common ones
21+
are in \'.workflows\` relatively to the repository root directory.
22+
23+
Approximate command's output is
24+
\`\`\`bash
25+
==>> git elegant show-workflows
26+
.git/.workflows/accept-work-after
27+
.workflows/amend-work-ahead
28+
.workflows/amend-work-after
29+
.workflows/release-work-after
30+
.workflows/save-work-ahead
31+
.workflows/save-work-after
32+
....
33+
\`\`\`
34+
MESSAGE
35+
}
36+
37+
--list() {
38+
if test -e "${1}" ; then
39+
echo "${1}"
40+
fi
41+
}
42+
43+
default() {
44+
for command in $(git elegant show-commands); do
45+
--list $(personal-workflows-file ${command} ahead)
46+
--list $(personal-workflows-file ${command} after)
47+
--list $(common-workflows-file ${command} ahead)
48+
--list $(common-workflows-file ${command} after)
49+
done
50+
}

libexec/plugins/workflows

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
--prefix(){
4+
if [[ ! "init-repository clone-repository" =~ ${1} ]]; then
5+
git rev-parse --show-cdup 2>/dev/null
6+
fi
7+
}
8+
9+
personal-workflows() {
10+
# usage: personal-workflows <command>
11+
echo "$(--prefix ${1}).git/.workflows"
12+
}
13+
14+
common-workflows() {
15+
# usage: common-workflows <command>
16+
echo "$(--prefix ${1}).workflows"
17+
}
18+
19+
personal-workflows-file() {
20+
# usage: personal-workflows-file <comand> <type>
21+
echo "$(personal-workflows ${1})/${1}-${2}"
22+
}
23+
24+
common-workflows-file() {
25+
# usage: common-workflows-file <comand> <type>
26+
echo "$(common-workflows ${1})/${1}-${2}"
27+
}

tests/git-elegant-show-commands.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ teardown() {
2929
"show-release-notes"
3030
"release-work"
3131
"polish-work"
32+
"show-workflows"
3233
)
3334
check git-elegant show-commands
3435
[[ ${#lines[@]} -eq ${#COMMANDS[@]} ]]

tests/git-elegant-show-workflows.bats

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bats
2+
3+
load addons-common
4+
load addons-repo
5+
6+
setup() {
7+
repo-new
8+
}
9+
10+
teardown(){
11+
repo-clean
12+
}
13+
14+
@test "'show-workflows': displays all available workflow files" {
15+
repo "mkdir -p .workflows .git/.workflows"
16+
repo "echo echo ahead git > .git/.workflows/start-work-ahead"
17+
repo "echo echo ahead no > .workflows/start-work-ahead"
18+
repo "echo echo after git > .git/.workflows/start-work-after"
19+
repo "echo echo after no > .workflows/start-work-after"
20+
repo "ls -lah .git/.workflows/* .workflows/*"
21+
check git-elegant show-workflows
22+
[[ ${status} -eq 0 ]]
23+
[[ ${lines[0]} =~ ".git/.workflows/start-work-ahead" ]]
24+
[[ ${lines[1]} =~ ".git/.workflows/start-work-after" ]]
25+
[[ ${lines[2]} =~ ".workflows/start-work-ahead" ]]
26+
[[ ${lines[3]} =~ ".workflows/start-work-after" ]]
27+
}

0 commit comments

Comments
 (0)