Skip to content

Commit

Permalink
Add --help text to generated shell scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrieb committed Dec 24, 2023
1 parent a93501f commit e81e3e6
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
62 changes: 53 additions & 9 deletions just_sh/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,8 @@ def color_variables() -> str:
GREEN="$(test "${SHOW_COLOR}" = 'true' && printf "\\033[32m" || echo)"
PINK="$(test "${SHOW_COLOR}" = 'true' && printf "\\033[35m" || echo)"
BLUE="$(test "${SHOW_COLOR}" = 'true' && printf "\\033[34m" || echo)"
TICK="$(printf '%s' '`')"
DOLLAR="$(printf '%s' '$')"
"""

def assign_variables_function() -> str:
Expand Down Expand Up @@ -1397,7 +1399,7 @@ def list_fn() -> str:
LIST_PREFIX="${{1}}"
;;
--unsorted)
-u|--unsorted)
SORTED="false"
;;
esac
Expand Down Expand Up @@ -1533,7 +1535,7 @@ def helper_functions() -> str:
summarizefn() {{
while [ "$#" -gt 0 ]; do
case "${{1}}" in
--unsorted)
-u|--unsorted)
SORTED="false"
;;
esac
Expand All @@ -1543,6 +1545,48 @@ def helper_functions() -> str:
{recipe_summaries()}
}}
usage() {{
cat <<EOF
${{GREEN}}just.sh${{NOCOLOR}} {__version__}
Jacob Strieb
Auto-generated from a Justfile by just.sh - https://github.com/jstrieb/just.sh
${{YELLOW}}USAGE:${{NOCOLOR}}
./just.sh [FLAGS] [OPTIONS] [ARGUMENTS]...
${{YELLOW}}FLAGS:${{NOCOLOR}}
${{GREEN}}--choose${{NOCOLOR}} Select one or more recipes to run using a binary. If ${{TICK}}--chooser${{TICK}} is not passed the chooser defaults to the value of ${{DOLLAR}}JUST_CHOOSER, falling back to ${{TICK}}fzf${{TICK}}
${{GREEN}}--dump${{NOCOLOR}} Print justfile
${{GREEN}}--evaluate${{NOCOLOR}} Evaluate and print all variables. If a variable name is given as an argument, only print that variable's value.
${{GREEN}}--init${{NOCOLOR}} Initialize new justfile in project root
${{GREEN}}-l, --list${{NOCOLOR}} List available recipes and their arguments
${{GREEN}}--summary${{NOCOLOR}} List names of available recipes
${{GREEN}}-u, --unsorted${{NOCOLOR}} Return list and summary entries in source order
${{GREEN}}-h, --help${{NOCOLOR}} Print help information
${{GREEN}}-V, --version${{NOCOLOR}} Print version information
${{YELLOW}}OPTIONS:${{NOCOLOR}}
${{GREEN}}--chooser <CHOOSER>${{NOCOLOR}} Override binary invoked by ${{TICK}}--choose${{TICK}}
${{GREEN}}--list-heading <TEXT>${{NOCOLOR}} Print <TEXT> before list
${{GREEN}}--list-prefix <TEXT>${{NOCOLOR}} Print <TEXT> before each list item
${{GREEN}}--set <VARIABLE> <VALUE>${{NOCOLOR}} Override <VARIABLE> with <VALUE>
${{GREEN}}--shell <SHELL>${{NOCOLOR}} Invoke <SHELL> to run recipes
${{GREEN}}--shell-arg <SHELL-ARG>${{NOCOLOR}} Invoke shell with <SHELL-ARG> as an argument
${{YELLOW}}ARGS:${{NOCOLOR}}
${{GREEN}}<ARGUMENTS>...${{NOCOLOR}} Overrides and recipe(s) to run, defaulting to the first recipe in the justfile
EOF
}}
err_usage() {{
cat <<EOF >&2
USAGE:
./just.sh [FLAGS] [OPTIONS] [ARGUMENTS]...
For more information try ${{GREEN}}--help${{NOCOLOR}}
EOF
}}
{list_fn()}
{dump_fn()}
Expand Down Expand Up @@ -1613,7 +1657,7 @@ def main_entrypoint() -> str:
{target_cases}
# Built-in flags
--list)
-l|--list)
shift
listfn "$@"
RUN_DEFAULT="false"
Expand Down Expand Up @@ -1644,7 +1688,7 @@ def main_entrypoint() -> str:
shift
;;
--unsorted)
-u|--unsorted)
SORTED="false"
shift
;;
Expand All @@ -1661,7 +1705,7 @@ def main_entrypoint() -> str:
shift
;;
--version)
-V|--version)
shift
echo "just.sh {__version__}"
echo
Expand All @@ -1670,10 +1714,9 @@ def main_entrypoint() -> str:
break
;;
--help)
-h|--help)
shift
echo "No --help text yet..." >&2
# TODO
usage
RUN_DEFAULT="false"
break
;;
Expand Down Expand Up @@ -1745,7 +1788,8 @@ def main_entrypoint() -> str:
-*)
echo_error "Found argument '${{NOCOLOR}}${{YELLOW}}${{1}}${{NOCOLOR}}${{BOLD}}' that wasn't expected, or isn't valid in this context"
# TODO: Print usage/--help
echo >&2
err_usage
exit 1
;;
Expand Down
5 changes: 4 additions & 1 deletion test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def permuted_combinations(fixed: Any, *args: Any, fix_first: bool = False) -> Li
)
],
["--evaluate"],
# Don't compare --help output - just.sh implements only some of the flags
# ["--help"],
# Don't compare dump output – just reformats and canonicalizes the dump
# ["--dump"],
]
Expand Down Expand Up @@ -1150,7 +1152,8 @@ def test_evalute_without_quoting() -> None:
(re.compile(rb"\d{1,2}:\d{1,2}"), rb"12:00"), # Normalize times
(re.compile(rb"\nDid you mean[^\n]*"), rb""),
(re.compile(rb"which wasn't expected"), rb"that wasn't expected"),
(re.compile(rb"\n\nUSAGE:\n(.+|\n+)+"), rb""),
# (re.compile(rb"(.+\n.+\n.+)?\n\nUSAGE:\n(.+|\n+)+"), rb""), # TODO: Remove
(re.compile(rb"\[--\]\s*"), rb""),
(
re.compile(rb"(\s*-->[^\n]*\n)?\s*\|[^\n]*\n\s*\d*?\s*\|[^\n]*\n\s*\|[^\n]*"),
rb"",
Expand Down

0 comments on commit e81e3e6

Please sign in to comment.