Skip to content

Commit

Permalink
fix(help): highlight not found in yellow
Browse files Browse the repository at this point in the history
  • Loading branch information
adoyle-h committed Dec 2, 2022
1 parent e97c4b2 commit a0fe95a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions one-cmds/help
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ print_help() {
local file="$ONE_DIR/one-cmds/$cmd"
local label arg

if [[ ! -x "$file" ]]; then
printf '%s: Not found sub-command "%s". No executable file: %s\n' 'one.bash' "$cmd" "$file" >&2
if [[ ! -x "${file}" ]]; then
printf '%bNot found command "%s".%b\n' "$YELLOW" "$cmd" "$RESET_ALL" >&2
return "$ONE_EX_USAGE"
fi

label=$( grep -i '^# one.bash:usage' "$file" 2>/dev/null || true )

if [[ -z "$label" ]]; then
echo "The command '$cmd' has not usage document." >&2
printf '%bThe command "%s" has not usage document.%b\n' "$YELLOW" "$cmd" "$RESET_ALL" >&2
return "$ONE_EX_UNAVAILABLE"
fi

Expand Down
17 changes: 10 additions & 7 deletions one-cmds/help-sub
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ fi
# shellcheck source=../deps/colors.bash
. "$ONE_DIR/deps/colors.bash"

# shellcheck source=../bash/exit-codes.bash
. "$ONE_DIR/bash/exit-codes.bash"

colorful() {
local line
while IFS=$'\n' read -r line; do
Expand All @@ -68,21 +71,21 @@ print_help() {
fi
done

if [[ ! -f ${file:-} ]]; then
printf '%s: Not found ONE_SUB command "%s".\n' 'one.bash' "$cmd" >&2
return 2
if [[ -z ${file:-} ]]; then
printf '%bNot found ONE_SUB command "%s".%b\n' "$YELLOW" "$cmd" "$RESET_ALL" >&2
return "$ONE_EX_USAGE"
fi

if [[ ! -x "${file}" ]]; then
printf '%s: Not found ONE_SUB command "%s". No executable file: %s\n' 'one.bash' "$cmd" "$file" >&2
return 1
printf '%bNot found ONE_SUB command "%s". File is not executable or not existed: %s%b\n' "$YELLOW" "$cmd" "$file" "$RESET_ALL" >&2
return "$ONE_EX_USAGE"
fi

label=$( grep -i '^# one.bash:usage' "$file" 2>/dev/null || true )

if [[ -z "$label" ]]; then
echo "The command '$cmd' has not usage document." >&2
return 0
printf '%bThe command "%s" has not usage document.%b\n' "$YELLOW" "$cmd" "$RESET_ALL" >&2
return "$ONE_EX_UNAVAILABLE"
fi

arg=$( sed -E 's/^# one.bash:usage(:?.*)/\1/i' <<<"$label" || true )
Expand Down

0 comments on commit a0fe95a

Please sign in to comment.