Skip to content

Commit

Permalink
Polish existing messages
Browse files Browse the repository at this point in the history
Introduce `question-text` command which is responsible for the printing
of questions and use it everywhere to ask a user about something.

Also, apply to `acquire-repository` and `obtain-work` `text` plugin and
polish messages.

#167
  • Loading branch information
extsoft committed Sep 14, 2019
1 parent 4565878 commit a4ac749
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 28 deletions.
6 changes: 3 additions & 3 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ as regular Git commands.
Approximate commands flow is
```bash
==> git elegant acquire-repository
################ Part 1 ################
################ User-specific options ################
git config --local user.name "Dmytro Serdiuk"
git config --local user.email "[email protected]"
git config --local core.editor vim
################ Part 2 ################
################ Mandatory options ################
# "|" char starts non-message lines while writing commit message
git config --local core.commentChar |
# Remove whitespaces when apply a patch
Expand All @@ -105,7 +105,7 @@ git config --local rebase.autoStash false
# Specify an external helper to be called when a username
# or password credential is needed (MAC only)
git config --local credential.helper osxkeychain
################ Part 3 ################
################ Aliases ################
# Remove local aliases which contain Elegant Git commands
git config --local --unset <alias>
# Add aliases for current commands
Expand Down
8 changes: 4 additions & 4 deletions libexec/git-elegant
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ __loop_ask() {
local m="$1"; shift
[ -z "$1" ] && return 0
for i in $@; do
info-text "$m [$i] "
question-text "$m [$i] (y/n):"
read answer
if [ -z "$answer" ]; then
if [[ "${answer}" == "y" ]]; then
eval "$c $i"
fi
done
Expand All @@ -59,9 +59,9 @@ __batch() {
local MM="$1"; shift
local AM="$1"; shift
local CM="$1"; shift
info-text "$MM "
question-text "$MM (y/n): "
read answer
if [ -z "$answer" ]; then
if [[ "${answer}" == "y" ]]; then
__loop "$CM" $@
else
__loop_ask "$CM" "$AM" $@
Expand Down
27 changes: 15 additions & 12 deletions libexec/git-elegant-acquire-repository
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ as regular Git commands.
Approximate commands flow is
\`\`\`bash
==> git elegant acquire-repository
################ Part 1 ################
################ User-specific options ################
git config --local user.name "Dmytro Serdiuk"
git config --local user.email "[email protected]"
git config --local core.editor vim
################ Part 2 ################
################ Mandatory options ################
# "|" char starts non-message lines while writing commit message
git config --local core.commentChar |
# Remove whitespaces when apply a patch
Expand All @@ -85,7 +85,7 @@ git config --local rebase.autoStash false
# Specify an external helper to be called when a username
# or password credential is needed (MAC only)
git config --local credential.helper osxkeychain
################ Part 3 ################
################ Aliases ################
# Remove local aliases which contain Elegant Git commands
git config --local --unset <alias>
# Add aliases for current commands
Expand All @@ -97,17 +97,17 @@ MESSAGE
__ask_question() {
# usage: __ask_options <prefix>
# it makes available ANSWER available
message=$(eval "echo -n \$${1}_message")
echo -n "$message"
default=$(eval "echo -n \$${1}_default")
if [[ -n "$default" ]]; then echo -n " {$default}"; fi
echo -n ": "
local message=$(eval "echo -n \$${1}_message")
local default=$(eval "echo -n \$${1}_default")
if [[ -n "$default" ]]; then message="${message} {$default}"; fi
question-text "${message}: "
read answer
export ANSWER=${answer:-$default}
}

__interactive-configuration() {
info-box "Interactive configuration. Please hit enter if you wish {default value}."
info-box "Configuring user-specific options..."
info-text "Please hit enter if you wish {default value}."
FUNCTIONS=$@
for f in ${FUNCTIONS[@]}; do
unset ANSWER
Expand All @@ -122,6 +122,7 @@ __interactive-configuration() {

__mandatory-configuration() {
# usage: __mandatory-configuration <name of array> ...
info-box "Configuring mandatory options..."
for config in ${@}; do
local os=$(uname -s)
if [[ "Darwin Linux" =~ "${os}" ]]; then
Expand All @@ -137,21 +138,23 @@ __mandatory-configuration() {
done
}
__remove-old-aliases() {
info-box "Removing old Git Elegant aliases..."
old_aliases=($(git config --get-regexp ^alias\. | grep "elegant " | cut -f 1 -d " "))
if [[ ${#old_aliases[@]} -ne 0 ]]; then
local counter=0
for old in ${old_aliases[@]}; do
git-verbose config --local --unset ${old} &&
counter=$((counter+1)) ||
info-box "Non-local alias! Remove it if needed using 'git config --global --unset ${old}'"
info-text "Non-local alias! Remove it if needed using 'git config --global --unset ${old}'"
done
info-box "${counter} git aliases were removed that contained 'elegant git' reference."
info-text "${counter} git aliases were removed that contained 'elegant git' reference."
else
info-box "There are no git aliases which contain 'elegant git' reference."
info-text "There are no git aliases which contain 'elegant git' reference."
fi
}

__aliases-configuration() {
info-box "Configuring Elegant Git aliases..."
for command in ${@}; do
local alias=${command}
local origin="elegant ${command}"
Expand Down
4 changes: 2 additions & 2 deletions libexec/git-elegant-obtain-work
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ default() {
$(git for-each-ref --format='%(refname:strip=2)' refs/remotes/** | grep "${PATTERN}")
)
if [[ ${#REMOTE_BRANCHES[@]} > 1 ]]; then
echo "The following branches are found:"
info-text "The following branches are found:"
for branch in ${REMOTE_BRANCHES[@]}; do
echo " - ${branch}"
info-text " - ${branch}"
done
error-box "Please re-run the command with concrete branch name from the list above!"
exit 43
Expand Down
16 changes: 13 additions & 3 deletions libexec/plugins/text
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ TEXT_FORMAT_BOLD=1
TEXT_FORMAT_UNDERLINE=4
TEXT_FORMAT_BLINKING=5

--colored-text() {
# usage: --colored-text <format> <color> <message>...
--colored-line() {
# usage: --colored-line <format> <color> <message>...
local COLOR=""
local RESET=""
if [[ -t 1 ]]; then
Expand All @@ -33,6 +33,11 @@ TEXT_FORMAT_BLINKING=5
prefix=" "
done
printf "${RESET}"
}

--colored-text() {
# usage: --colored-text <format> <color> <message>...
--colored-line "$@"
printf "\n"
}

Expand Down Expand Up @@ -76,4 +81,9 @@ error-text() {
error-box() {
# Display an error message within a multi-line log
--box-text error-text "$@"
}
}

question-text() {
# Display a question on current cursor's line
--colored-line ${TEXT_FORMAT_NORMAL} ${TEXT_COLOR_PURPLE} "$@"
}
8 changes: 4 additions & 4 deletions tests/git-elegant-acquire-repository.bats
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,20 @@ teardown() {
gitrepo git config --local "alias.bbb" "\"elegant bbb\""
check git-elegant acquire-repository
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "== 2 git aliases were removed that contained 'elegant git' reference. ==" ]]
[[ "${lines[@]}" =~ "2 git aliases were removed that contained 'elegant git' reference." ]]
}

@test "'acquire-repository': global aliases aren't removed" {
gitrepo git config --global "alias.glb" "\"elegant glb\""
check git-elegant acquire-repository
gitrepo git config --global --unset "alias.glb"
[[ "$status" -eq 0 ]]
[[ "${lines[@]}" =~ "== Non-local alias! Remove it if needed using 'git config --global --unset alias.glb' ==" ]]
[[ "${lines[@]}" =~ "== 0 git aliases were removed that contained 'elegant git' reference. ==" ]]
[[ "${lines[@]}" =~ "Non-local alias! Remove it if needed using 'git config --global --unset alias.glb'" ]]
[[ "${lines[@]}" =~ "0 git aliases were removed that contained 'elegant git' reference." ]]
}

@test "'acquire-repository': removing existing git aliases works as expected when aliases are absent" {
check git-elegant acquire-repository
[[ "${status}" -eq 0 ]]
[[ "${lines[@]}" =~ "== There are no git aliases which contain 'elegant git' reference. ==" ]]
[[ "${lines[@]}" =~ "There are no git aliases which contain 'elegant git' reference." ]]
}

0 comments on commit a4ac749

Please sign in to comment.