Table of Contents

Class ArgumentOption

Namespace
Webefinity.Switch
Assembly
Switch.dll

The ArgumentOption is the definition of an option. It can define long and short versions of the flag, as in --long and -s. A value provider accepts the string in the field after the flag, and converts it to an appropriate value for the option. Once the argument is parsed by the ArgumentHandler, the value provider holds and serves the values of the parsed arguments.

You can use the fluent extensions to add a varierty of value providers, to mark the option as required, and to mark it as Default.

A default option can be passed as the first argument on the command line without the flag. This is a good way to handle commands.

public class ArgumentOption
Inheritance
ArgumentOption
Inherited Members
Extension Methods

Constructors

ArgumentOption(string, char?, bool)

Create a new argument option, defining the long and short versions, and whether this is the single default command.

public ArgumentOption(string longVersion, char? shortVersion, bool isDefault)

Parameters

longVersion string

A long flag, matched as --{longVersion} against the arguments

shortVersion char?

An optional short flag, matched as -{shortVersion}, or null for no short version.

isDefault bool

Is this the default argument? A default argument as the first argument does not require the flag.

Properties

Default

Is this a default argument?

A command argument might be defined as: builder.Add("command", isDefault: true).AcceptString()

Calling the command line "Command the_command" would then cause "the_command" to be the value of the "command" argument. There is only one Default flag.

public bool Default { get; }

Property Value

bool

Description

The description of this option, for the usage output.

public string Description { get; }

Property Value

string

Long

The long argument flag.

public string Long { get; }

Property Value

string

Required

Do we require a value to be passed on the command line for this option?

public bool Required { get; }

Property Value

bool

Short

The short argument flag. Null if the short version is not used.

public char? Short { get; }

Property Value

char?

ValueProvider

The value provider for this option.

public IValueProvider? ValueProvider { get; }

Property Value

IValueProvider

Methods

AddProvider(IValueProvider)

Add a custom provider for this option

public ArgumentOption AddProvider(IValueProvider valueProvider)

Parameters

valueProvider IValueProvider

The custom provider instance.

Returns

ArgumentOption

This option, for fluid extensions.

IsMatch(string)

Check an argument to see if it is a matching flag for this option?

public bool IsMatch(string arg)

Parameters

arg string

The argument string

Returns

bool

True, if the argument matches the flag for this option.

MakeRequired()

Mark this option as required.

public ArgumentOption MakeRequired()

Returns

ArgumentOption

WithDescription(string)

Provide an option description for the usage.

public ArgumentOption WithDescription(string description)

Parameters

description string

Returns

ArgumentOption