apple / swift-argument-parser

Straightforward, type-safe argument parsing for Swift
Apache License 2.0
3.31k stars 311 forks source link

Add possibility for subcommand to show help text by default #560

Closed revolter closed 1 year ago

revolter commented 1 year ago

Similar to how pod cache works, meaning, it outputs the same thing as pod cache --help, it would be nice if this package would support it as well.

I tried this hacky workaround:

@Flag
var help = true

but it fails with the error

ArgumentParser/ParsableArguments.swift:256: Fatal error: Validation failed for `ConfigCommand`:

- One or more Boolean flags is declared with an initial value of `true`.
This results in the flag always being `true`, no matter whether the user
specifies the flag or not.

To resolve this error, change the default to `false`, provide a value
for the `inversion:` parameter, or remove the `@Flag` property wrapper
altogether.

Affected flag(s):
--help
natecook1000 commented 1 year ago

This is the default for how commands should work — can you provide an example of this not working as expected?

revolter commented 1 year ago

Oh, I thought that the run function is required, and I also didn't read its documentation.