The week in .NET – Command Line Parser Library, .NET South East

Bertrand Le Roy

Previous posts:

Package of the week: Command Line Parser Library

Command-line applications typically accept arguments and options, and expose a --help page describing them. Parsing those arguments and options is a repetitive task that .NET provides little help for out of the box, beyond the string[] args argument to main. Giacomo Stelluti Scala‘s Command Line Parser Library offers CLR applications a clean and concise API for manipulating command line arguments and related tasks, such as defining switches, options and verb commands. It allows you to display a help screen with a high degree of customization and a simple way to report syntax errors to the end user. Everything that is boring and repetitive about parsing command line arguments is delegated to the library, letting developers concentrate on core logic. It’s written in C# and doesn’t depend on other packages. It’s also friendly to F# and VB developers.

First, define the options the application expects:

class Options {
  [Option('r', "read", Required = true,
    HelpText = "Input files to be processed.")]
  public IEnumerable<string> InputFiles { get; set; }

  // Omitting long name, default --verbose
  [Option(
    HelpText = "Prints all messages to standard output.")]
  public bool Verbose { get; set; }

  [Option(Default = "中文",
    HelpText = "Content language.")]
  public string Language { get; set; }

  [Value(0, MetaName = "offset",
    HelpText = "File offset.")]
  public long? Offset { get; set; }
}

Then consume them:

static int Main(string[] args) {
  var options = new Options();
  var isValid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options);

User group of the week: .NET South East (Brighton, UK)

User groups are an essential part of the .NET Community, and none of them has existed forever. The creation of a new user group is an occasion for celebration. Steve Gordon, a regular of this column, did just that, and created the .NET South East user group in Brighton in the United Kingdom. I really like that Steve didn’t stop there, and went on explaining why and how he created the group in a great blog post. Hopefully, this can inspire others in the .NET community to create their own group: if there’s no user group in your area, but you know the users are there, just go ahead and fill that void!

.NET

ASP.NET

C#

F#

There is more content available this week in F# Weekly. If you want to see more F# awesomeness, please check it out!

Xamarin

Azure

UWP

Data

Game development

And this is it for this week!

Contribute to the week in .NET

As always, this weekly post couldn’t exist without community contributions, and I’d like to thank all those who sent links and tips. The F# section is provided by Phillip Carter, the gaming section by Stacey Haffner, the Xamarin section by Dan Rigby, and the Azure and UWP section by Michael Crump.

You can participate too. Did you write a great blog post, or just read one? Do you want everyone to know about an amazing new contribution or a useful library? Did you make or play a great game built on .NET? We’d love to hear from you, and feature your contributions on future posts. Please add your posts, it takes only a second.

We pick the articles based on the following criteria: the posts must be about .NET, they must have been published this week, and they must be original contents. Publication in Week in .NET is not an endorsement from Microsoft or the authors of this post.

This week’s post (and future posts) also contains news I first read on The ASP.NET Community Standup, on Weekly Xamarin, on F# weekly, and on The Morning Brew.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Giacomo Stelluti Scala 0

    Sorry, I see it only these days… Anyway great article and thank you!
    Giacomo S. S.
    (gsscoder)

Feedback usabilla icon