iffy / nim-argparse

Argument parsing for Nim
MIT License
120 stars 8 forks source link

FR: allow marking args/flags/options as global or exclusive to no subcommands #80

Open ZoomRmc opened 2 years ago

ZoomRmc commented 2 years ago

It would be very useful to be able to have two types of arguments/flags/options:

  1. Common to all invocations of the program, including all subcommands or no subcommands
  2. Conflicting with any subcommands

Syntax proposal:

var p = newParser:
  flag("-n", "--dryrun") # common
  rootCommand:
    arg("input") # can't be used with `frobnicate`
  command("frobnicate"):
    flag("-b")
    arg("subcommandInput")
iffy commented 2 years ago

Thanks for this suggestion!

Note to self (or whoever does it) when doing this: this might be a good opportunity to add a default command option, too. So you can explicitly run ./prog foo -a but if foo is the default command ./prog -a is equivalent.