Re: Command line help options
- Posted by jeremy (admin) Nov 29, 2010
- 1310 views
Sorry but -h, --help or brackets... all the same: hardcoding such things is not standard.
Regarding help, an example is enough: On Unix, command ls (DIR on Windows) -obviously one of the most frequently used commands-, not only does not use -h for help but for another purpose:
-h, --human-readable, with -l, print sizes in human-readable format (e.g., 1K 234M 2G)
Um, the user can easily over ride -h and --help. The user has complete control if they want to:
- Over ride and use --get-help, -u or whatever to display help
- Provide no default help options at all
It's always been this way. There was a bug that I did fix which prevented the no help at all from being recognized, but it was there from the get go. As for hard coding, I'll stick to the idea that -h and --help should be hard coded as that is a logical default that the vast majority of applications will use w/o any issue. If they localize their application, then they can override that the values with their localized values. Euphoria fully supports this.
I gave an example before about how to do this, here is another:
sequence opts = { { "h", "--human-readable", "Display sizes in a human readable format (e.g., 1K, 234M, 2G)", { NO_PARAMETER } } }
The above will cause the -h or --human-readable to flip a boolean value to YES, via the long name "human-readable". When looking at the help message from the application with this help sequence it will contain 3 entries, -h/--human-readable, --help and -?.
If you do not like either of those, you have two choices, give your own parameters for help:
sequence opts = { { "h", "--human-readable", "Display sizes in a human readable format (e.g., 1K, 234M, 2G)", { NO_PARAMETER } }, { "s", 0, "Admit you are (s)tuck and want help", { HELP } } }
In which case there will be two options presented, -h/--human-readable and -s. If you give -s on the command line, cmd_parse will give the help message as the current -h/--help does. Or, you can specify you don't want cmd_parse() to handle any help options, you may want to do something totally on your own:
sequence opts = { { "h", "--human-readable", "Display sizes in a human readable format (e.g., 1K, 234M, 2G)", { NO_PARAMETER } } } map optvals = cmd_parse(ops, { NO_HELP })
Does that cover what you wish to do, minus the removal of the brackets for now?
Jeremy