jdx / usage

A specification for CLIs
https://usage.jdx.dev
MIT License
151 stars 6 forks source link

Unexpected behavior with flag #162

Open arthurh4 opened 2 weeks ago

arthurh4 commented 2 weeks ago

hello, i'm currently testing the usage support for mise task and testing the --force flag from the example.

I have the following script:

#!/usr/bin/env bash
#USAGE flag "-f --force" help="Overwrite existing <file>" count=true
#USAGE flag "-u --user <user>" help="User to run as"
#USAGE arg "<file>" help="The file to write" default="file.txt"
#USAGE arg "<arg_with_default>" help="An arg with a default" default="mydefault"
#MISE description="This is a test cmd1 script"
#MISE alias="cd1"
echo "all: $@"
echo "usage_force: $usage_force"
echo "usage_user: $usage_user"
echo "usage_file: $usage_file"
echo "usage_arg_with_default: $usage_arg_with_default"

but when running several tests:

# mise run java:cmd1 -f
[java:cmd1] $ ~/.config/mise/tasks/java/cmd1
all:
usage_force:
usage_user:
usage_file: file.txt
usage_arg_with_default: mydefault
# mise run java:cmd1 -f --user=test
[java:cmd1] $ ~/.config/mise/tasks/java/cmd1 --user=test
all: --user=test
usage_force:
usage_user: test
usage_file: file.txt
usage_arg_with_default: mydefault
# mise run java:cmd1 -f --user=test -f
[java:cmd1] $ ~/.config/mise/tasks/java/cmd1 --user=test -f
all: --user=test -f
usage_force: true
usage_user: test
usage_file: file.txt
usage_arg_with_default: mydefault

you can see that -f only become true when the user flag is also set and the -f is set after the user flag, is this an expected behavior ? or am I missing something ? thank you

jdx commented 2 weeks ago

you need to use mise run -- java:cmd1 -f to prevent mise run from grabbing -f