I am redesigning a command line application and am looking for a way to make its use more intuitive. Are there any conventions for the format of parameters passed into a command line application? Or any other method that people have found useful?
相关问题
- JFX scale image up and down to parent
- softlinks atime and mtime modification
- Get unexpanded argument from bash command line
- Include and Execute EXE in C# Command Line App
- Batch - Set variables in for loop
相关文章
- Algorithm for maximizing coverage of rectangular a
- Compile and build with single command line Java (L
- Is there a way to hide the new HTML5 spinbox contr
- Can keyboard of type UIKeyboardTypeNamePhonePad be
- PropertyGrid - Possible to have a file/directory s
- Programming a touch screen application with SWING
- Can WM_NEXTDLGCTL be used with non-dialog windows?
- How to update command line output?
This is definitely true. I'm not certain about dos-prompt conventions, but on unix-like systems the general conventions are roughly:
1) Formatting is
2) Single character parameters (such as 'x') are passed as -x 3) Multi character parameters (such as 'add-keys') are passed as --add-keys
I've just released an even better command line parser.
https://github.com/gene-l-thomas/coptions
It's on nuget Install-Package coptions
Supports automatic --help generation, verbs, e.g. commmand.exe
Enjoy.
Complementing @vonc's answer, don't accept ambiguous abbreviations. Eg:
In fact, in that case, I probably wouldn't accept an abbreviation for "destroy"...
I always add a /? parameter to get help and I always try to have a default (i.e. most common scenario) implementation.
Otherwise I tend to use the "/x" for switches and "/x:value" for switches that require values to be passed. Makes it pretty easy to parse the parameters using regular expressions.
I've created a .Net C# library that includes a command-line parser. You just need to create a class that inherits from the CmdLineObject class, call Initialize, and it will automatically populate the properties. It can handle conversions to different types (uses an advanced conversion library also included in the project), arrays, command-line aliases, click-once arguments, etc. It even automatically creates command-line help (/?).
If you are interested, the URL to the project is http://bizark.codeplex.com. It is currently only available as source code.
I see a lot of Windows command line specifics, but if your program is intended for Linux, I find the GNU command line standard to be the most intuitive. Basically, it uses double hyphens for the long form of a command (e.g.,
--help
) and a single hyphen for the short version (e.g.,-h
). You can also "stack" the short versions together (e.g.,tar -zxvf
filename
) and mix 'n match long and short to your heart's content.The GNU site also lists standard option names.
The getopt library greatly simplifies parsing these commands. If C's not your bag, Python has a similar library, as does Perl.