diff --git a/just_sh/convert.py b/just_sh/convert.py index 2063f50..d562b9b 100644 --- a/just_sh/convert.py +++ b/just_sh/convert.py @@ -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: @@ -1397,7 +1399,7 @@ def list_fn() -> str: LIST_PREFIX="${{1}}" ;; - --unsorted) + -u|--unsorted) SORTED="false" ;; esac @@ -1533,7 +1535,7 @@ def helper_functions() -> str: summarizefn() {{ while [ "$#" -gt 0 ]; do case "${{1}}" in - --unsorted) + -u|--unsorted) SORTED="false" ;; esac @@ -1543,6 +1545,48 @@ def helper_functions() -> str: {recipe_summaries()} }} +usage() {{ + cat <${{NOCOLOR}} Override binary invoked by ${{TICK}}--choose${{TICK}} + ${{GREEN}}--list-heading ${{NOCOLOR}} Print before list + ${{GREEN}}--list-prefix ${{NOCOLOR}} Print before each list item + ${{GREEN}}--set ${{NOCOLOR}} Override with + ${{GREEN}}--shell ${{NOCOLOR}} Invoke to run recipes + ${{GREEN}}--shell-arg ${{NOCOLOR}} Invoke shell with as an argument + +${{YELLOW}}ARGS:${{NOCOLOR}} + ${{GREEN}}...${{NOCOLOR}} Overrides and recipe(s) to run, defaulting to the first recipe in the justfile +EOF +}} + +err_usage() {{ + cat <&2 +USAGE: + ./just.sh [FLAGS] [OPTIONS] [ARGUMENTS]... + +For more information try ${{GREEN}}--help${{NOCOLOR}} +EOF +}} + {list_fn()} {dump_fn()} @@ -1613,7 +1657,7 @@ def main_entrypoint() -> str: {target_cases} # Built-in flags - --list) + -l|--list) shift listfn "$@" RUN_DEFAULT="false" @@ -1644,7 +1688,7 @@ def main_entrypoint() -> str: shift ;; - --unsorted) + -u|--unsorted) SORTED="false" shift ;; @@ -1661,7 +1705,7 @@ def main_entrypoint() -> str: shift ;; - --version) + -V|--version) shift echo "just.sh {__version__}" echo @@ -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 ;; @@ -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 ;; diff --git a/test/test.py b/test/test.py index 30d713d..81d709a 100644 --- a/test/test.py +++ b/test/test.py @@ -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"], ] @@ -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"",