CLArgs
GitHubNuGetSamplesAbout
v2
v2
  • CLArgs - The .NET command-line parser
  • Functionality explained
    • Demo2 - Simple Math
      • Display Help
      • Settings
    • Demo3 - Extended Math
      • Sum Command
      • Analze Command
    • Demo4 - Custom Extensions
    • Demo5 - Logging and printing
      • Printing
    • Demo6 - Context Sets
      • Argument Files
  • Migrate from v1
Powered by GitBook
On this page
  • The Command and the Context
  • Use your application
  • What's next

CLArgs - The .NET command-line parser

Documentation

NextFunctionality explained

Last updated 2 months ago

CLArgs (Command-Line Arguments) is a Command-Line parser for .NET!

  • The most powerful

  • The easiest to use

  • The most flexible

CLArgs V2 is completely new! It was built with the latest .NET 6 builder concepts in mind.

Version 1 is still part of the CLArgs Assembly so that your existing v1 application won't break. However, v1 is not longer supported or maintained and I want to encourage you to !

class Program
{
    public static void Main(string[] args)
    {
        CommandHostBuilder.Create(args).Start();
    }
}

The implementation of the application's functionality, together with all the is provided using Commands and Contexts.

The Command and the Context

A Command implements the functionality that is executed (Verb). A Command uses a Context to define the supported arguments.

[Command( "HelloWorld", 
  helpText: "A simple command to print a name in the Console Window.")]
public class HelloWorldCommand : CommandBase2<HelloWorldContext>
{
    public HelloWorldCommand(IServiceProvider serviceProvider) 
        : base(serviceProvider) {}

    protected override void Execute()
    {
        // Use the Context of type HelloWorldContext
        // to access your command-line arguments.
        Console.WriteLine($"Hello {Context.Name}");
    }
}

The HelloWorldContext describes a single option, only.

public class HelloWorldContext
{
    [OptionDescriptor("Name", new[] { "n" },
        Default = "John Doe", Required = false,
        HelpText = "Specify the name of the person you want to say 'Hello'.")]
    public string? Name { get; set; }
}

Use your application

> yourApp /n "Markus Schmidt"
Hello Markus Schmidt
> yourApp /?

HelloWorld          A simple command to print a name in the Console Window.
--------------------------------------------------------------------------------
/Name               Tags=n optional
                    Specify the name of the person you want to say 'Hello'.
                    DEFAULT: 'John Doe'

What's next

See .

upgrade to version 2
help-information
how to display help