▲ | einpoklum 3 days ago | |||||||
Exactly the opposite of this. We should parse the command-line using _no_ strict types. Not even integers. Nothing beyond parsing its structure, e.g. which option names get which (string) values, and which flags are enabled. This can be done without knowing _anything_ about the application domain, and provide a generic options structure which is no longer a sequence of characters. This approach IMNSHO is much cleaner than the intrication of cmdline parser libraries with application logic and application-domain-related types. Then one can specify validation logic declaratively, and apply it generically. This has the added benefit - for compiled rather than interpreted library - of not having to recompile the CLI parsing library for each different app and each different definition of options. | ||||||||
▲ | MrJohz 3 days ago | parent | next [-] | |||||||
Can you give some examples of this working well? It certainly goes against all of my experience working with CLIs and with parsing inputs in general (e.g. web APIs etc). In general, I've found that the quicker I can convert strings into rich types, the easier that code is to work with and the less likely I am to have troubles with invalid data. | ||||||||
| ||||||||
▲ | bakkoting 18 hours ago | parent | prev [-] | |||||||
This is the approach taken by node's built-in argument parser util.parseArgs. |