> For the complete documentation index, see [llms.txt](https://mspro.gitbook.io/clargs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mspro.gitbook.io/clargs/readme.md).

# CLArgs - The .NET command-line parser

Documentation

*CLArgs (**C**ommand-**L**ine **Arg**ument**s**)* is a **Command-Line parser for .NET!**

* The most powerful
* The easiest to use
* The most flexible

{% hint style="warning" %}
CLArgs V2 is completely new! \
It was built with the latest *.NET 6 builder* concepts in mind.&#x20;

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 [upgrade to version 2](/clargs/migrate-from-v1.md)!
{% endhint %}

{% code lineNumbers="true" %}

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

{% endcode %}

The implementation of the application's functionality, together with all the [help-information](/clargs/functionality-explained/demo2-simple-math/display-help.md) 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.&#x20;

{% code lineNumbers="true" %}

```csharp
[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}");
    }
}
```

{% endcode %}

The `HelloWorldContext` describes a single option, only.

{% code lineNumbers="true" %}

```csharp
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; }
}
```

{% endcode %}

See [how to display help](/clargs/functionality-explained/demo2-simple-math/display-help.md).

### Use your application

<pre><code><strong>> yourApp /n "Markus Schmidt"
</strong>Hello Markus Schmidt
</code></pre>

```
> 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

*
