Suggestions for implementation of a command line i

2019-01-30 11:42发布

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?

17条回答
贼婆χ
2楼-- · 2019-01-30 12:02

Here's a CodeProject article that might help you out...

C#/.NET Command Line Arguments Parser

IF VB is your flavor, here's a separate article (with a bit more guidance related content) to check out...

Parse and Validate Command Line Parameters with VB.NET

查看更多
Root(大扎)
3楼-- · 2019-01-30 12:04

If you use one of the standard tools for generating command line interfaces, like getopts, then you'll conform automatically.

查看更多
【Aperson】
4楼-- · 2019-01-30 12:06

If you are using C# try Mono.GetOptions, it's a very powerful and simple-to-use command-line argument parser. It works in Mono environments and with Microsoft .NET Framework.

EDIT: Here are a few features

  • Each param has 2 CLI representations (1 character and string, e.g. -a or --add)
  • Default values
  • Strongly typed
  • Automagically produces an help screen with instructions
  • Automagically produces a version and copyright screen
查看更多
相关推荐>>
5楼-- · 2019-01-30 12:10

Best thing to do is don't assume anything if you can. When the operator types in your application name for execution and does not have any parameters either hit them with a USAGE block or in the alternative open a Windows Form and allow them to enter everything you need.

c:\>FOO

FOO

USAGE FOO -{Option}{Value}

-A Do A stuff
-B Do B stuff

c:\>

Parameter delimiting I place under the heading of a religious topic: hyphens(dashes), double hyphens, slashes, nothing, positional, etc.

You didn't indicate your platform, but for the next comment I will assume Windows and .net

You can create a console based application in .net and allow it to interact with the Desktop using Forms just by choosing the console based project then adding the Windows.Forms, System.Drawing, etc DLLs.

We do this all the time. This assures that no one takes a turn down a dark alley.

查看更多
兄弟一词,经得起流年.
6楼-- · 2019-01-30 12:10

If you're using Perl, my CLI::Application framework might be just what you need. It lets you build applications with a SVN/CVS/GIT like user interface easily ("your-command -o --long-opt some-action-to-execute some parameters").

查看更多
登录 后发表回答