←back to thread

203 points dahlia | 1 comments | | HN request time: 0.001s | source
Show context
einpoklum ◴[] No.45157404[source]
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.

replies(2): >>45157472 #>>45185433 #
1. bakkoting ◴[] No.45185433[source]
This is the approach taken by node's built-in argument parser util.parseArgs.