Skip to content

Cannot print help of non-shell scripts #405

@muzimuzhi

Description

@muzimuzhi

For shell script, for example ./examples/example.sh in this repo, both

  • usage bash --help ./examples/example.sh and
  • usage bash ./examples/example.sh --help

print help of the script.

However for non-shell scripts (with shebang #!/usr/bin/env -S usage exec <cmd>), for example the ./examples/test-usage-double-slash.js in this repo, none of

  • usage exec node --help ./examples/test-usage-double-slash.js
  • usage exec node ./examples/test-usage-double-slash.js --help

print help of the script. They both print help for usage exec.

$ cat <<EOF >./greet
#!/usr/bin/env -S usage exec node
//USAGE flag "-f --force" help="Overwrite existing <file>"
//USAGE flag "-u --user <user>" help="User to run as"
//USAGE arg "<file>" help="The file to write" default="file.txt"

const { usage_user, usage_force, usage_file } = process.env;

console.log("Force overwrite:", usage_force);
console.log("User:", usage_user);
console.log("Writing to file:", usage_file);
EOF

$ chmod +x greet

$ ./greet -fu Jimmy
Force overwrite: true
User: Jimmy
Writing to file: file.txt

$ ./greet --help
Execute a script, parsing args and exposing them as environment variables

Usage: usage exec <COMMAND> <BIN> [ARGS]...

Arguments:
  <COMMAND>  command to execute after parsing usage spec
  <BIN>      path to script to execute
  [ARGS]...  arguments to pass to script

Options:
  -h, --help  Print help

$ usage exec node --help ./greet
# help for "usage exec"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions