Show / Hide Table of Contents

Class CommandLineParser

Defines a class for parsing command line arguments. The following types of command line arguments are supported:

Argument typeDescription
Named argumentsRepresents a named command line argument
Option argumentsRepresents a command line option
Plain argumentsRepresents any raw command line argument

A named argument consists of two raw arguments. The first argument determines an argument name and the second argument an actual argument value. Argument names must be prefixed by an argument name prefix. For example, -workingFolder C:\Temp is a valid named argument. Character '-' is the default named argument prefix.

An option argument consists of an option prefix, option name, option name-value separator and an actual option value. For example, /BufferSize:12345 is a valid option argument. Characters '/' and ':' are the default option prefix and option name-value separator, respectively. If a value part is missing from an option argument, it’s assumed to be a boolean option with the default value of true. Thus, the option arguments /SaveLog and /SaveLog:true are equivalent.

A plain argument is any raw argument that doesn’t fall into the two categories above. In other words, all raw arguments that are not prefixed either by an argument name prefix or an option prefix, are treated as plain arguments.

Inheritance
System.Object
CommandLineParser
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Namespace: Juhta.Net.Console
Assembly: Juhta.Net.Console.dll
Syntax
public class CommandLineParser

Properties

| Improve this Doc View Source

HasUnconsumedArguments

Gets a boolean value determining whether this CommandLineParser instance has unconsumed arguments.

Declaration
public bool HasUnconsumedArguments { get; }
Property Value
Type Description
System.Boolean

Methods

| Improve this Doc View Source

GetNamedArgument(String)

Gets a named argument.

Declaration
public NamedArgument GetNamedArgument(string argumentName)
Parameters
Type Name Description
System.String argumentName

Specifies an argument name.

Returns
Type Description
NamedArgument

Returns an instance of NamedArgument holding the specified named argument.

Remarks

If the specified named argument is not found, an exception will be thrown.

| Improve this Doc View Source

GetNamedArgument(String, String)

Gets a named argument.

Declaration
public NamedArgument GetNamedArgument(string argumentName, string defaultValue)
Parameters
Type Name Description
System.String argumentName

Specifies an argument name.

System.String defaultValue

Specifies a default value for the named argument. Can be null.

Returns
Type Description
NamedArgument

Returns an instance of NamedArgument holding the specified named argument.

Remarks

If the specified named argument is not found and defaultValue is null, an exception will be thrown.

| Improve this Doc View Source

GetOptionArgument(String)

Gets an option argument.

Declaration
public OptionArgument GetOptionArgument(string optionName)
Parameters
Type Name Description
System.String optionName

Specifies an option name.

Returns
Type Description
OptionArgument

Returns an instance of OptionArgument holding the specified option argument.

Remarks

If the specified option is not found, an exception will be thrown.

| Improve this Doc View Source

GetOptionArgument(String, String)

Gets an option argument.

Declaration
public OptionArgument GetOptionArgument(string optionName, string defaultValue)
Parameters
Type Name Description
System.String optionName

Specifies an option name.

System.String defaultValue

Specifies a default value for the option argument. Can be null.

Returns
Type Description
OptionArgument

Returns an instance of OptionArgument holding the specified option argument.

Remarks

If the specified option is not found and defaultValue is null, an exception will be thrown.

| Improve this Doc View Source

GetPlainArgument(Int32)

Gets a plain argument.

Declaration
public PlainArgument GetPlainArgument(int index)
Parameters
Type Name Description
System.Int32 index

Specifies a plain argument index. The index of the first plain argument is 0.

Returns
Type Description
PlainArgument

Returns an instance of PlainArgument holding the specified plain argument.

Remarks

If the specified plain argument is not found, an exception will be thrown.

| Improve this Doc View Source

GetPlainArgument(Int32, String)

Gets a plain argument.

Declaration
public PlainArgument GetPlainArgument(int index, string defaultValue)
Parameters
Type Name Description
System.Int32 index

Specifies a plain argument index. The index of the first plain argument is 0.

System.String defaultValue

Specifies a default value for the plain argument. Can be null.

Returns
Type Description
PlainArgument

Returns an instance of PlainArgument holding the specified plain argument.

Remarks

If the specified plain argument is not found and defaultValue is null, an exception will be thrown.

| Improve this Doc View Source

GetUnconsumedArguments()

Gets all unconsumed command line arguments.

Declaration
public CommandLineArgument[] GetUnconsumedArguments()
Returns
Type Description
CommandLineArgument[]

Returns an array of CommandLineArgument objects not yet consumed.

| Improve this Doc View Source

ParseArguments(String[])

Parses an array of raw command line arguments.

Declaration
public void ParseArguments(string[] arguments)
Parameters
Type Name Description
System.String[] arguments

Specifies an array of raw command line arguments.

| Improve this Doc View Source

ParseArguments(String[], String, String, String)

Parses an array of raw command line arguments.

Declaration
public void ParseArguments(string[] arguments, string argumentNamePrefix, string optionPrefix, string optionNameValueSeparator)
Parameters
Type Name Description
System.String[] arguments

Specifies an array of raw command line arguments.

System.String argumentNamePrefix

Specifies an argument name prefix.

System.String optionPrefix

Specifies an option prefix.

System.String optionNameValueSeparator

Specifies an option name-value separator.

  • Improve this Doc
  • View Source
Back to top Copyright © 2017-2019 Juha Lähteenmäki
Generated by DocFX