实现命令行界面的建议

时间:2021-08-09 12:17:55

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 个解决方案

#1


28  

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.

我看到很多Windows命令行细节,但是如果你的程序是针对Linux的,我发现GNU命令行标准是最直观的。基本上,它使用双连字符作为命令的长形式(例如, - help)和短版本的单个连字符(例如,-h)。您还可以将短版本“堆叠”在一起(例如,tar -zxvf文件名),并将'n'匹配为您的心脏内容的长短。

The GNU site also lists standard option names.

GNU站点还列出了标准选项名称。

The getopt library greatly simplifies parsing these commands. If C's not your bag, Python has a similar library, as does Perl.

getopt库极大地简化了解析这些命令的过程。如果C不是你的包,那么Python就像Perl一样拥有类似的库。

#2


13  

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.

如果你正在使用C#try Mono.GetOptions,它是一个非常强大且易于使用的命令行参数解析器。它适用于Mono环境和Microsoft .NET Framework。

EDIT: Here are a few features

编辑:这里有一些功能

  • Each param has 2 CLI representations (1 character and string, e.g. -a or --add)
  • 每个param有2个CLI表示(1个字符和字符串,例如-a或--add)

  • Default values
  • Strongly typed
  • Automagically produces an help screen with instructions
  • 自动生成带有说明的帮助屏幕

  • Automagically produces a version and copyright screen
  • 自动生成版本和版权屏幕

#3


4  

One thing I like about certain CLI is the usage of shortcuts.
I.e, all the following lines are doing the same thing

我喜欢某些CLI的一件事是使用快捷方式。即,以下所有行都在做同样的事情

myCli.exe describe someThing
myCli.exe descr someThing
myCli.exe desc someThing

That way, the user may not have to type the all command every time.

这样,用户可能不必每次都输入all命令。

#4


4  

A good and helpful reference:

一个好的和有用的参考:

https://commandline.codeplex.com/

Library available via NuGet:

通过NuGet提供的图书馆:

  1. Latest stable: Install-Package CommandLineParser.
  2. 最新稳定版:Install-Package CommandLineParser。

  3. Latest release: Install-Package CommandLineParser -pre.
  4. 最新版本:Install-Package CommandLineParser -pre。

One line parsing using default singleton: CommandLine.Parser.Default.ParseArguments(...).
One line help screen generator: HelpText.AutoBuild(...).
Map command line arguments to IList<string>, arrays, enum or standard scalar types.
Plug-In friendly architecture as explained here.
Define verb commands as git commit -a.
Create parser instance using lambda expressions.

使用默认单例解析一行:CommandLine.Parser.Default.ParseArguments(...)。一行帮助屏幕生成器:HelpText.AutoBuild(...)。将命令行参数映射到IList ,数组,枚举或标准标量类型。插件友好的架构,如此处所述。将动词命令定义为git commit -a。使用lambda表达式创建解析器实例。

QuickStart: https://commandline.codeplex.com/wikipage?title=Quickstart&referringTitle=Documentation

// Define a class to receive parsed values
class Options {
  [Option('r', "read", Required = true,
    HelpText = "Input file to be processed.")]
  public string InputFile { get; set; }

  [Option('v', "verbose", DefaultValue = true,
    HelpText = "Prints all messages to standard output.")]
  public bool Verbose { get; set; }

  [ParserState]
  public IParserState LastParserState { get; set; }

  [HelpOption]
  public string GetUsage() {
    return HelpText.AutoBuild(this,
      (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
  }
}

// Consume them
static void Main(string[] args) {
  var options = new Options();
  if (CommandLine.Parser.Default.ParseArguments(args, options)) {
    // Values are available here
    if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile);
  }
}

#5


3  

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.

最好的办法是尽可能不做任何事情。当操作员键入您的应用程序名称以执行并且没有任何参数时,可以使用USAGE块命中它们,或者在替代方法中打开Windows窗体并允许它们输入您需要的所有内容。

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

您没有指明您的平台,但对于下一个评论,我将假设Windows和.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.

您可以在.net中创建基于控制台的应用程序,并允许它使用Forms与桌面交互,只需选择基于控制台的项目,然后添加Windows.Forms,System.Drawing等DLL。

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

我们一直这样做。这确保没有人转过一条黑暗的小巷。

#6


3  

Command line conventions vary from OS to OS, but the convention that's probably gotten both the most use, and the most public scrutiny is the one supported by the GNU getopt package. See http://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html for more info.

命令行约定因操作系统而异,但可能获得最多使用和最公开审查的约定是GNU getopt包支持的约定。有关详细信息,请参阅http://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html。

It allows you to mix single letter commands, such as -nr, with longer, self-documenting options, such as --numeric --reverse. Be nice, and implement a --help (-?) option and then your users will be able to figure out all they need to know.

它允许您将单个字母命令(如-nr)与较长的自记录选项(如--numeric --reverse)混合使用。很好,并实现--help( - ?)选项,然后您的用户将能够找出他们需要知道的所有内容。

#7


3  

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

这是CodeProject文章可能会帮助你...

C#/.NET Command Line Arguments Parser

C#/ .NET命令行参数解析器

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

如果VB是你的味道,这里有一篇单独的文章(有更多的指导相关内容)来检查...

Parse and Validate Command Line Parameters with VB.NET

使用VB.NET解析和验证命令行参数

#8


3  

Complementing @vonc's answer, don't accept ambiguous abbreviations. Eg:

补充@ vonc的答案,不要接受含糊不清的缩写。例如:

  myCli.exe describe someThing
  myCli.exe destroy someThing
  myCli.exe des someThing ???

In fact, in that case, I probably wouldn't accept an abbreviation for "destroy"...

事实上,在这种情况下,我可能不会接受“破坏”的缩写...

#9


2  

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.

否则,我倾向于使用“/ x”表示开关,而“/ x:value”表示需要传递值的开关。使用正则表达式解析参数非常容易。

#10


1  

I developed this framework, maybe it helps:

我开发了这个框架,也许它有帮助:

The SysCommand is a powerful cross-platform framework, to develop Console Applications in .NET. Is simple, type-safe, and with great influences of the MVC pattern.

SysCommand是一个功能强大的跨平台框架,用于在.NET中开发控制台应用程序。简单,类型安全,并受MVC模式的巨大影响。

https://github.com/juniorgasparotto/SysCommand

namespace Example.Initialization.Simple
{
    using SysCommand.ConsoleApp;

    public class Program
    {
        public static int Main(string[] args)
        {
            return App.RunApplication();
        }
    }

    // Classes inheriting from `Command` will be automatically found by the system
    // and its public properties and methods will be available for use.
    public class MyCommand : Command
    {
        public void Main(string arg1, int? arg2 = null)
        {
            if (arg1 != null)
                this.App.Console.Write(string.Format("Main arg1='{0}'", arg1));
            if (arg2 != null)
                this.App.Console.Write(string.Format("Main arg2='{0}'", arg2));
        }

        public void MyAction(bool a)
        {
            this.App.Console.Write(string.Format("MyAction a='{0}'", a));
        }
    }
}

Tests:

// auto-generate help
$ my-app.exe help

// method "Main" typed
$ my-app.exe --arg1 value --arg2 1000

// or without "--arg2"
$ my-app.exe --arg1 value

// actions support
$ my-app.exe my-action -a

#11


0  

-operation [parameters] -command [your command] -anotherthings [otherparams]....

-operation [parameters] -command [your command] -anotherthings [otherparams] ....

For example,

YourApp.exe -file %YourProject.prj% -Secure true

#12


0  

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

如果您使用标准工具之一生成命令行界面(如getopts),那么您将自动符合。

#13


0  

The conventions that you use for you application would depend on

您为应用程序使用的约定将取决于

1) What type of application it is. 2) What operating system you are using.

1)它是什么类型的应用程序。 2)您正在使用的操作系统。

This is definitely true. I'm not certain about dos-prompt conventions, but on unix-like systems the general conventions are roughly:

这绝对是真的。我不确定dos-prompt约定,但在类Unix系统上,一般约定大致如下:

1) Formatting is

1)格式化

appName parameters

2) Single character parameters (such as 'x') are passed as -x 3) Multi character parameters (such as 'add-keys') are passed as --add-keys

2)单个字符参数(例如'x')作为-x 3传递。多字符参数(例如'add-keys')作为--add-keys传递

#14


0  

The conventions that you use for you application would depend on

您为应用程序使用的约定将取决于

1) What type of application it is.
2) What operating system you are using. Linux? Windows? They both have different conventions.

1)它是什么类型的应用程序。 2)您正在使用的操作系统。 Linux呢?视窗?它们都有不同的惯例。

What I would suggest is look at other command line interfaces for other commands on your system, paying special attention to the parameters passed. Having incorrect parameters should give the user solution directed error message. An easy to find help screen can aid in usability as well.

我建议的是查看系统上其他命令的其他命令行界面,特别注意传递的参数。参数不正确应该为用户提供解决方案定向错误消息。易于查找的帮助屏幕也有助于实现可用性。

Without know what exactly your application will do, it's hard to give specific examples.

不知道你的应用程序究竟会做什么,很难给出具体的例子。

#15


0  

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").

如果您使用的是Perl,我的CLI :: Application框架可能就是您所需要的。它允许您轻松地使用SVN / CVS / GIT(如用户界面)构建应用程序(“您的命令-o --long-opt some-action-to-execute some parameters”)。

#16


0  

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 (/?).

我创建了一个包含命令行解析器的.Net C#库。您只需要创建一个继承自CmdLineObject类的类,调用Initialize,它将自动填充属性。它可以处理不同类型的转换(使用项目中也包含的高级转换库),数组,命令行别名,单击一次参数等。它甚至可以自动创建命令行帮助(/?)。

If you are interested, the URL to the project is http://bizark.codeplex.com. It is currently only available as source code.

如果您有兴趣,该项目的URL是http://bizark.codeplex.com。它目前仅作为源代码提供。

#17


0  

I've just released an even better command line parser.
https://github.com/gene-l-thomas/coptions
It's on nuget Install-Package coptions

我刚刚发布了一个更好的命令行解析器。 https://github.com/gene-l-thomas/coptions这是关于nuget安装包的问题

using System;
using System.Collections.Generic;
using coptions;

[ApplicationInfo(Help = "This program does something useful.")]
public class Options
{
    [Flag('s', "silent", Help = "Produce no output.")]
    public bool Silent;

    [Option('n', "name", "NAME", Help = "Name of user.")]
    public string Name
    {
        get { return _name;  }
        set { if (String.IsNullOrWhiteSpace(value))
                throw new InvalidOptionValueException("Name must not be blank");
              _name = value;
        }
    }
    private string _name;

    [Option("size", Help = "Size to output.")]
    public int Size = 3;

    [Option('i', "ignore", "FILENAME", Help = "Files to ignore.")]
    public List<string> Ignore;

    [Flag('v', "verbose", Help = "Increase the amount of output.")]
    public int Verbose = 1;

    [Value("OUT", Help = "Output file.")]
    public string OutputFile;

    [Value("INPUT", Help = "Input files.")]
    public List<string> InputFiles;
}

namespace coptions.ReadmeExample
{
    class Program
    {
        static int Main(string[] args)
        {
            try
            {
                Options opt = CliParser.Parse<Options>(args);

                Console.WriteLine(opt.Silent);
                Console.WriteLine(opt.OutputFile);
                return 0;
            }
            catch (CliParserExit)
            {
                // --help
                return 0;

            } catch (Exception e)
            {
                // unknown options etc...
                Console.Error.WriteLine("Fatal Error: " + e.Message);
                return 1;
            }
        }
    }
}

Supports automatic --help generation, verbs, e.g. commmand.exe
Enjoy.

支持自动 - 帮助生成,动词,例如commmand.exe享受。

#1


28  

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.

我看到很多Windows命令行细节,但是如果你的程序是针对Linux的,我发现GNU命令行标准是最直观的。基本上,它使用双连字符作为命令的长形式(例如, - help)和短版本的单个连字符(例如,-h)。您还可以将短版本“堆叠”在一起(例如,tar -zxvf文件名),并将'n'匹配为您的心脏内容的长短。

The GNU site also lists standard option names.

GNU站点还列出了标准选项名称。

The getopt library greatly simplifies parsing these commands. If C's not your bag, Python has a similar library, as does Perl.

getopt库极大地简化了解析这些命令的过程。如果C不是你的包,那么Python就像Perl一样拥有类似的库。

#2


13  

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.

如果你正在使用C#try Mono.GetOptions,它是一个非常强大且易于使用的命令行参数解析器。它适用于Mono环境和Microsoft .NET Framework。

EDIT: Here are a few features

编辑:这里有一些功能

  • Each param has 2 CLI representations (1 character and string, e.g. -a or --add)
  • 每个param有2个CLI表示(1个字符和字符串,例如-a或--add)

  • Default values
  • Strongly typed
  • Automagically produces an help screen with instructions
  • 自动生成带有说明的帮助屏幕

  • Automagically produces a version and copyright screen
  • 自动生成版本和版权屏幕

#3


4  

One thing I like about certain CLI is the usage of shortcuts.
I.e, all the following lines are doing the same thing

我喜欢某些CLI的一件事是使用快捷方式。即,以下所有行都在做同样的事情

myCli.exe describe someThing
myCli.exe descr someThing
myCli.exe desc someThing

That way, the user may not have to type the all command every time.

这样,用户可能不必每次都输入all命令。

#4


4  

A good and helpful reference:

一个好的和有用的参考:

https://commandline.codeplex.com/

Library available via NuGet:

通过NuGet提供的图书馆:

  1. Latest stable: Install-Package CommandLineParser.
  2. 最新稳定版:Install-Package CommandLineParser。

  3. Latest release: Install-Package CommandLineParser -pre.
  4. 最新版本:Install-Package CommandLineParser -pre。

One line parsing using default singleton: CommandLine.Parser.Default.ParseArguments(...).
One line help screen generator: HelpText.AutoBuild(...).
Map command line arguments to IList<string>, arrays, enum or standard scalar types.
Plug-In friendly architecture as explained here.
Define verb commands as git commit -a.
Create parser instance using lambda expressions.

使用默认单例解析一行:CommandLine.Parser.Default.ParseArguments(...)。一行帮助屏幕生成器:HelpText.AutoBuild(...)。将命令行参数映射到IList ,数组,枚举或标准标量类型。插件友好的架构,如此处所述。将动词命令定义为git commit -a。使用lambda表达式创建解析器实例。

QuickStart: https://commandline.codeplex.com/wikipage?title=Quickstart&referringTitle=Documentation

// Define a class to receive parsed values
class Options {
  [Option('r', "read", Required = true,
    HelpText = "Input file to be processed.")]
  public string InputFile { get; set; }

  [Option('v', "verbose", DefaultValue = true,
    HelpText = "Prints all messages to standard output.")]
  public bool Verbose { get; set; }

  [ParserState]
  public IParserState LastParserState { get; set; }

  [HelpOption]
  public string GetUsage() {
    return HelpText.AutoBuild(this,
      (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
  }
}

// Consume them
static void Main(string[] args) {
  var options = new Options();
  if (CommandLine.Parser.Default.ParseArguments(args, options)) {
    // Values are available here
    if (options.Verbose) Console.WriteLine("Filename: {0}", options.InputFile);
  }
}

#5


3  

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.

最好的办法是尽可能不做任何事情。当操作员键入您的应用程序名称以执行并且没有任何参数时,可以使用USAGE块命中它们,或者在替代方法中打开Windows窗体并允许它们输入您需要的所有内容。

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

您没有指明您的平台,但对于下一个评论,我将假设Windows和.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.

您可以在.net中创建基于控制台的应用程序,并允许它使用Forms与桌面交互,只需选择基于控制台的项目,然后添加Windows.Forms,System.Drawing等DLL。

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

我们一直这样做。这确保没有人转过一条黑暗的小巷。

#6


3  

Command line conventions vary from OS to OS, but the convention that's probably gotten both the most use, and the most public scrutiny is the one supported by the GNU getopt package. See http://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html for more info.

命令行约定因操作系统而异,但可能获得最多使用和最公开审查的约定是GNU getopt包支持的约定。有关详细信息,请参阅http://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html。

It allows you to mix single letter commands, such as -nr, with longer, self-documenting options, such as --numeric --reverse. Be nice, and implement a --help (-?) option and then your users will be able to figure out all they need to know.

它允许您将单个字母命令(如-nr)与较长的自记录选项(如--numeric --reverse)混合使用。很好,并实现--help( - ?)选项,然后您的用户将能够找出他们需要知道的所有内容。

#7


3  

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

这是CodeProject文章可能会帮助你...

C#/.NET Command Line Arguments Parser

C#/ .NET命令行参数解析器

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

如果VB是你的味道,这里有一篇单独的文章(有更多的指导相关内容)来检查...

Parse and Validate Command Line Parameters with VB.NET

使用VB.NET解析和验证命令行参数

#8


3  

Complementing @vonc's answer, don't accept ambiguous abbreviations. Eg:

补充@ vonc的答案,不要接受含糊不清的缩写。例如:

  myCli.exe describe someThing
  myCli.exe destroy someThing
  myCli.exe des someThing ???

In fact, in that case, I probably wouldn't accept an abbreviation for "destroy"...

事实上,在这种情况下,我可能不会接受“破坏”的缩写...

#9


2  

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.

否则,我倾向于使用“/ x”表示开关,而“/ x:value”表示需要传递值的开关。使用正则表达式解析参数非常容易。

#10


1  

I developed this framework, maybe it helps:

我开发了这个框架,也许它有帮助:

The SysCommand is a powerful cross-platform framework, to develop Console Applications in .NET. Is simple, type-safe, and with great influences of the MVC pattern.

SysCommand是一个功能强大的跨平台框架,用于在.NET中开发控制台应用程序。简单,类型安全,并受MVC模式的巨大影响。

https://github.com/juniorgasparotto/SysCommand

namespace Example.Initialization.Simple
{
    using SysCommand.ConsoleApp;

    public class Program
    {
        public static int Main(string[] args)
        {
            return App.RunApplication();
        }
    }

    // Classes inheriting from `Command` will be automatically found by the system
    // and its public properties and methods will be available for use.
    public class MyCommand : Command
    {
        public void Main(string arg1, int? arg2 = null)
        {
            if (arg1 != null)
                this.App.Console.Write(string.Format("Main arg1='{0}'", arg1));
            if (arg2 != null)
                this.App.Console.Write(string.Format("Main arg2='{0}'", arg2));
        }

        public void MyAction(bool a)
        {
            this.App.Console.Write(string.Format("MyAction a='{0}'", a));
        }
    }
}

Tests:

// auto-generate help
$ my-app.exe help

// method "Main" typed
$ my-app.exe --arg1 value --arg2 1000

// or without "--arg2"
$ my-app.exe --arg1 value

// actions support
$ my-app.exe my-action -a

#11


0  

-operation [parameters] -command [your command] -anotherthings [otherparams]....

-operation [parameters] -command [your command] -anotherthings [otherparams] ....

For example,

YourApp.exe -file %YourProject.prj% -Secure true

#12


0  

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

如果您使用标准工具之一生成命令行界面(如getopts),那么您将自动符合。

#13


0  

The conventions that you use for you application would depend on

您为应用程序使用的约定将取决于

1) What type of application it is. 2) What operating system you are using.

1)它是什么类型的应用程序。 2)您正在使用的操作系统。

This is definitely true. I'm not certain about dos-prompt conventions, but on unix-like systems the general conventions are roughly:

这绝对是真的。我不确定dos-prompt约定,但在类Unix系统上,一般约定大致如下:

1) Formatting is

1)格式化

appName parameters

2) Single character parameters (such as 'x') are passed as -x 3) Multi character parameters (such as 'add-keys') are passed as --add-keys

2)单个字符参数(例如'x')作为-x 3传递。多字符参数(例如'add-keys')作为--add-keys传递

#14


0  

The conventions that you use for you application would depend on

您为应用程序使用的约定将取决于

1) What type of application it is.
2) What operating system you are using. Linux? Windows? They both have different conventions.

1)它是什么类型的应用程序。 2)您正在使用的操作系统。 Linux呢?视窗?它们都有不同的惯例。

What I would suggest is look at other command line interfaces for other commands on your system, paying special attention to the parameters passed. Having incorrect parameters should give the user solution directed error message. An easy to find help screen can aid in usability as well.

我建议的是查看系统上其他命令的其他命令行界面,特别注意传递的参数。参数不正确应该为用户提供解决方案定向错误消息。易于查找的帮助屏幕也有助于实现可用性。

Without know what exactly your application will do, it's hard to give specific examples.

不知道你的应用程序究竟会做什么,很难给出具体的例子。

#15


0  

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").

如果您使用的是Perl,我的CLI :: Application框架可能就是您所需要的。它允许您轻松地使用SVN / CVS / GIT(如用户界面)构建应用程序(“您的命令-o --long-opt some-action-to-execute some parameters”)。

#16


0  

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 (/?).

我创建了一个包含命令行解析器的.Net C#库。您只需要创建一个继承自CmdLineObject类的类,调用Initialize,它将自动填充属性。它可以处理不同类型的转换(使用项目中也包含的高级转换库),数组,命令行别名,单击一次参数等。它甚至可以自动创建命令行帮助(/?)。

If you are interested, the URL to the project is http://bizark.codeplex.com. It is currently only available as source code.

如果您有兴趣,该项目的URL是http://bizark.codeplex.com。它目前仅作为源代码提供。

#17


0  

I've just released an even better command line parser.
https://github.com/gene-l-thomas/coptions
It's on nuget Install-Package coptions

我刚刚发布了一个更好的命令行解析器。 https://github.com/gene-l-thomas/coptions这是关于nuget安装包的问题

using System;
using System.Collections.Generic;
using coptions;

[ApplicationInfo(Help = "This program does something useful.")]
public class Options
{
    [Flag('s', "silent", Help = "Produce no output.")]
    public bool Silent;

    [Option('n', "name", "NAME", Help = "Name of user.")]
    public string Name
    {
        get { return _name;  }
        set { if (String.IsNullOrWhiteSpace(value))
                throw new InvalidOptionValueException("Name must not be blank");
              _name = value;
        }
    }
    private string _name;

    [Option("size", Help = "Size to output.")]
    public int Size = 3;

    [Option('i', "ignore", "FILENAME", Help = "Files to ignore.")]
    public List<string> Ignore;

    [Flag('v', "verbose", Help = "Increase the amount of output.")]
    public int Verbose = 1;

    [Value("OUT", Help = "Output file.")]
    public string OutputFile;

    [Value("INPUT", Help = "Input files.")]
    public List<string> InputFiles;
}

namespace coptions.ReadmeExample
{
    class Program
    {
        static int Main(string[] args)
        {
            try
            {
                Options opt = CliParser.Parse<Options>(args);

                Console.WriteLine(opt.Silent);
                Console.WriteLine(opt.OutputFile);
                return 0;
            }
            catch (CliParserExit)
            {
                // --help
                return 0;

            } catch (Exception e)
            {
                // unknown options etc...
                Console.Error.WriteLine("Fatal Error: " + e.Message);
                return 1;
            }
        }
    }
}

Supports automatic --help generation, verbs, e.g. commmand.exe
Enjoy.

支持自动 - 帮助生成,动词,例如commmand.exe享受。