Skip to content

Showing an additional usage line for forced commands #527

@DannyBen

Description

@DannyBen

Discussed in #526

Originally posted by codevogel July 4, 2024
Say I have a bashly script foo that I run with ./foo

In my bashly.yml I have

commands:
  - name: do
    help: do something with my_arg
    default: force
    args:
      - name: my_arg
        help: my argument to be handled
        required: true

if I then run ./foo I get

❯ ./foo
missing required argument: MY_ARG
usage: foo do MY_ARG

This could be somewhat confusing to a new user, as they have just done foo, not foo do.
Also, ./foo MY_ARG would also be sufficient usage.

So, it would be nice if it instead printed

❯ ./foo
missing required argument: MY_ARG
usage: foo do MY_ARG
       foo MY_ARG

I don't see how I could achieve this with one of the custom_strings, as this would be behavior that is specific to the forced command only.

I tried looking at adding a src/after.sh to evaluate the last line of the output and seeing if it starts with usage: foo do to echo usage: foo MY_ARG, but after.sh does not run if the script already exists due to catching a usage error. It also seems like bad practice to do this with a before.sh

What would be the best way to enable this?

(An alternative way to render this would be something like)

❯ ./foo
missing required argument: MY_ARG
usage: foo MY_ARG
       foo do MY_ARG

or

❯ ./foo
missing required argument: MY_ARG
usage: foo do MY_ARG
 ( or: foo MY_ARG )
```</div>

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions