-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic argument parsing #117
Comments
One idea I've been toying with was "immediate mode" argument parser, with the API along the lines of const force = args.bool("-f/--force", "ignore errors")
const path = args.string("--path", "path to operate on", { required: true })
args.done() The trick would be that required From the other angle, clap-style derives are actually inconvenient for quick scripts, as they force you to declare a struct type for the CLI args, while, in the script, you often need only local variables. And I think low-effort option to add help text (or just to print the options themselves, without any human-authored help) is pretty valueable -- a common use-case are internal tools for a team of software engineers, where you don't necessary want to polish everything to be fit for the end-user, but you also don't want to bug your collegue-author in slack to learn how to use the tool. |
Not going to lie, but this feels outside the scope of dax. cliffy has a really good interface that is really easy to understand and create good CLI interfaces. |
I think it's in scope. Dax is meant to be a swiss army knife for automation scripts and being able to understand inputs to that script is important part of that. Both cliffy and deno_std don't really provide the kind of API I'm looking for in this case. |
Also agree out of scope. There is no necessity to couple such functionality, as it can just be composed. You could write your desired functionality as your own module. If you want something existing, I wrote this arg parser https://github.com/bevry/argument/blob/HEAD/source/example.ts based on the patterns from a decade of writing hundreds of commands in Dorothy https://github.com/bevry/dorothy - which I'm thinking of using dax for as a replacement for bash |
Yeah, I'm going to close this for now (mainly because I don't have the bandwidth atm) |
Generally when writing scripts, you don't need complex argument parsing and want something that can easily be figured out by looking at the code. You also don't need help text. For that reason, I think an approach like the following might be more appropriate than something more featureful like deno_std's argument parser.
More complex example:
args
to prevent the "unknown command" error (maybeargs.markHandled()
or something).$.args.hasFlag("force")
for--force
and$.args.hasFlag("f")
for-f
$.args.get("time"): Arg | undefined
-- always requires an equals sign$.args.getOrThrow("time"): Arg | undefined
$.args.getOrThrow("time").number()
$.args.throwUncapturedFlags()
- Throw for any flags that haven't been captured (maybe)The text was updated successfully, but these errors were encountered: