3 ms·
But every single command line parser I have ever used (and I have used many over the past 25 years in many programming languages) does in fact know before parsi
by saurik 6y ago
But every single command line parser I have ever used (and I have used many over the past 25 years in many programming languages) does in fact know before parsing that a b and c don't take a value and o does: accepting the grammar for the flags and then parsing them in this way is like the only job of the parser?
- TeMPOraL 6y agoI suppose the only reason why you wouldn't want to have a centralized description of the command line grammar is if you're using flags which alter the set of acceptable flags. Like e.g. if you put all git subcommands into one single executable - the combinations and meanings of commandline flags would become absurdly complicated.
- tom_ 6y agoThis is usually handled by adding support for that sort of syntax to the parsing library. The result is typically not complicated: you have a parser for the global options, then, if using subcommands, in effect a map of subcommand name to parser for options for that command.
- rabidrat 6y agoSome programs may allow for plugins which can have their own options. But you may want to provide an option for where to load the plugins from.