Search for an arsenal of command line arguments for .NET.

I am looking for a parser for command line arguments, for example, "Command Syntax Parser" from http://www.sellsbrothers.com/tools/Genghis/ .

Functions I am looking for:

  • Use auto generation
  • It is necessary to check the necessary and optional parameters
  • Parameters must support IEnumerable with separator support.
  • Flag options should be supported.
  • It would be nice to maintain a union of options like "/ fx" == "/ f / x"
  • It would be nice not to force a space after the parameter, for example, "/ftest.txt" == "/ f test.txt"

PS: The "command line parser" is pretty good, I really like its design, but there is no documentation, no new updates, and I could not figure out how to do this, for example, how to check the required parameters.

+78
command-line c # arguments
Mar 10 '09 at 17:22
source share
12 answers

My personal favorite third-party command line parsing library is โ€œCommand Lineโ€ , and I assume this is the one you're talking about. The most recent release was less than 2 months ago, and there are regular commits. If you want more mature sentences, you can cut out the console library in a monoproject (sorry, I cannot find a direct link to the namespace at the moment, but this is part of the mono-frame)

+52
Mar 10 '09 at 17:39
source share

Take a look at ndesk.options.

Now it is called Mono.Options .

+20
Mar 26 '09 at 12:47
source share

The popular and fairly comprehensive C command line parser is GNU getopt . This has been ported (or cloned) for C # /. NET several times. Some of them include:

Take your pick! There are several others, and Google can tell you about them,

+5
Mar 26 '09 at 13:07
source share

Unfortunately, there is no built-in support to handle this in a standard way. Have you looked into PowerShell? I am sure that in this shell there is a class that does exactly what you want or something like that.

+4
Mar 10 '09 at 17:27
source share

Edit: as fatcat1111 points out, this feature did not ship with the final version of .net 4.0.

C # 4.0 has a pretty good one. Probably not very useful so far, but you can think about what the jump to the built-in one will make simple when it comes out. Bart de Smith talked about it on his B # Blog

+2
Sep 09 '09 at 19:19
source share

I suggest NDesk.Options

look here:

Best way to parse command line arguments in C #?

+2
Jun 12 2018-11-11T00:
source share

Keep in mind that once you start using this parser, you will either have to support it yourself, or depend on someone else to support it for you. You might be better off writing your own, starting with your most important, urgent requirements. I found that it took a lot of work to complete the fairly complex command-line parsing for most of the console applications I worked on.

I also found that when parsing gets too complicated, it might be time to stop using the command line.

+1
Mar 10 '09 at 17:27
source share

I'm sure this is not exactly what you are looking for, but:

Someone here had this problem, and his first thought was โ€œhey, okamla is very good!โ€, And quickly ported it to F #.

+1
Mar 10 '09 at 17:44
source share

I use the parser from the C # 3.0 cookbook.

All examples from this book can be downloaded here: http://examples.oreilly.com/9780596516109/

Search for "Arguments" and you will find it. You have to make some small code changes to get rid of all this in your own class, but this is not a big problem.

It supports all of your points except the last two (union and lack of a space).

+1
Mar 12 '09 at 12:58
source share

The BizArk library contains a command line parser.

Basically, you just create a class that inherits CmdLineObject, add the properties you want to populate from the command line, add CmdLineArgAttribute to the properties, and then call Initialize in your program. It also supports ClickOnce! URL arguments!

Features (from the site) ...

  • Automatic initialization: class properties are automatically set based on command line arguments.
  • Default properties: send the value without specifying a property name.
  • Conversion of values. Uses the powerful ConvertEx class, also included in BizArk, to convert values โ€‹โ€‹to the appropriate type.
  • Boolean flags. Flags can be set by simply using the argument (ex, / b for true and / b for false) or by adding true / false, yes / no, etc.
  • Argument Arrays. Just add a few values โ€‹โ€‹after the command line name to set a property that is defined as an array. Ex, / x 1 2 3 will populate x with the array {1, 2, 3} (assuming x is defined as an array of integers).
  • Command line aliases: a property can support multiple command line aliases. For example, Help uses an alias ?.
  • Partial name recognition. You do not need to specify a full name or alias, simply enough for the parser to remove the property / alias from others.
  • ClickOnce Support: Can initialize properties even if they are specified as a query string in the URL for ClickOnce deployed applications. The command line initialization method will determine if it works like ClickOnce or not, so your code does not need to be changed when using it.
  • Automatically creates /? help: This includes good formatting that takes into account the width of the console.
  • Load / save command line arguments to a file: This is especially useful if you have several large complex sets of command line arguments that you want to run several times.
+1
Jan 28 '11 at 17:11
source share

I am a fan of the C # port for OptParse, the Python built-in library. It is quite easy to use compared to most of the other offers here and contains a number of useful functions in addition to simple automatic analysis.

0
Sep 09 '09 at 19:23
source share

You may like my Rug.Cmd

Easy to use and extensible command line parser. Handles: Bool, Plus / Minus, String, String List, CSV, Enumeration.

Built in '/?' help mode.

Built in '/ ??' and '/? D '.

static void Main(string[] args) { // create the argument parser ArgumentParser parser = new ArgumentParser("ArgumentExample", "Example of argument parsing"); // create the argument for a string StringArgument StringArg = new StringArgument("String", "Example string argument", "This argument demonstrates string arguments"); // add the argument to the parser parser.Add("/", "String", StringArg); // parse arguemnts parser.Parse(args); // did the parser detect a /? argument if (parser.HelpMode == false) { // was the string argument defined if (StringArg.Defined == true) { // write its value RC.WriteLine("String argument was defined"); RC.WriteLine(StringArg.Value); } } } 

Edit: This is my project, and therefore this answer should not be considered as confirmation from a third party. However, I use it for every command line program that I write, it is open source, and I hope others can benefit from it.

0
Jan 23 '12 at 17:13
source share



All Articles