Class CommandArgsConfiguration
Provides implementation of configuration based on arguments supplied from command line which is "string[]". Arguments start with either "/" or "-" prefix. If any argument is not prefixed then it is written as an auto-named attribute node of the root with its value set, otherwise a section (under root) with argument's name is created. Any argument may have options. Any option may either consist of name or name value pair delimited by "=". Argument options are written as attribute nodes of their corresponding sections. If option value specified without name (without "=") then option is auto-named
Implements
Inherited Members
Namespace: Azos.Conf
Assembly: Azos.dll
Syntax
[Serializable]
public class CommandArgsConfiguration : Configuration, ICloneable
Examples
Given command line:
c:\>dosomething.exe "c:\input.file" "d:\output.file" -compress level=100 method=zip -shadow fast -large
The following configuration object will be created from the supplied args:
[args ?1="c:\input.file" ?2="c:\output.file"]
[compress level="100" method="zip"]
[shadow ?1="fast"]
[large]
Use args:
var conf = new CmdArgsConfiguration(args);
var inFile = conf.Root.AttrByIndex(0).ValueAsString(DEFAULT_INPUT_FILE);
var outFile = conf.Root.AttrByIndex(1).ValueAsString(DEFAULT_OUTPUT_FILE);
.....
if (conf.Root["large"].Exists) .......
.....
var level = conf.Root["compress"].AttrByName("level").ValueAsInt(DEFAULT_COMPRESSION_LEVEL);
.....
Constructors
CommandArgsConfiguration(String[])
Creates an instance of the new configuration parsed from command line arguments
Declaration
public CommandArgsConfiguration(string[] args)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | args |
CommandArgsConfiguration(String[], Boolean)
Creates an instance of the new configuration parsed from command line arguments
Declaration
public CommandArgsConfiguration(string[] args, bool inhibitSlashArg)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | args | |
System.Boolean | inhibitSlashArg |
Fields
ARG_PREFIX_DASH
Declaration
public const string ARG_PREFIX_DASH = "-"
Field Value
Type | Description |
---|---|
System.String |
ARG_PREFIX_SLASH
Declaration
public const string ARG_PREFIX_SLASH = "/"
Field Value
Type | Description |
---|---|
System.String |
OPTION_EQ
Declaration
public const char OPTION_EQ = '='
Field Value
Type | Description |
---|---|
System.Char |
ROOT_NODE_NAME
Declaration
public const string ROOT_NODE_NAME = "args"
Field Value
Type | Description |
---|---|
System.String |
Properties
Arguments
Returns arguments array that this configuration was parsed from
Declaration
public string[] Arguments { get; }
Property Value
Type | Description |
---|---|
System.String[] |
InhibitSlashArg
When true, disregards '/' as an argument delimiter
Declaration
public bool InhibitSlashArg { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsReadOnly
Indicates whether configuration is readonly or may be modified and saved
Declaration
public override bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |