« Command Line Parser Library » : différence entre les versions
Apparence
Aucun résumé des modifications |
|||
Ligne 1 : | Ligne 1 : | ||
[[Category:CSharp]] | |||
= Documentation = | = Documentation = | ||
* [https://github.com/commandlineparser/commandline GitHub project] | * [https://github.com/commandlineparser/commandline GitHub project] | ||
* [https://github.com/commandlineparser/commandline/wiki/Getting-Started Getting Started] | * [https://github.com/commandlineparser/commandline/wiki/Getting-Started Getting Started] | ||
= | = Options = | ||
<kode lang=cs> | <kode lang=cs> | ||
// créer une classe dont l'instance sera passée à la méthode ParseArguments | // créer une classe dont l'instance sera passée à la méthode ParseArguments | ||
Ligne 21 : | Ligne 22 : | ||
[Option('t', "option2", HelpText = "Option2.")] | [Option('t', "option2", HelpText = "Option2.")] | ||
public int Option2 { get; set; } | public int Option2 { get; set; } | ||
} | } | ||
</kode> | </kode> | ||
<kode lang= | = Parse = | ||
<kode lang=cs> | |||
var options = new Options(); | var options = new Options(); | ||
if (CommandLine.Parser.Default.ParseArguments(args, options)) | if (CommandLine.Parser.Default.ParseArguments(args, options)) | ||
Ligne 47 : | Ligne 38 : | ||
</kode> | </kode> | ||
<kode lang= | = Command line = | ||
- | {{info | By default options {{boxx|--help}} and {{boxx|--version}} are available.}} | ||
- | <kode lang=ps> | ||
-- | # option1 | ||
- | -o value | ||
- | -ovalue | ||
--option1 value | |||
--option1=value | |||
</kode> | </kode> | ||
Version du 26 mars 2020 à 16:09
Documentation
Options
// créer une classe dont l'instance sera passée à la méthode ParseArguments
class Options
{
[Usage(ApplicationAlias = "My Application")]
public static IEnumerable<Example> Examples => new List<Example>()
{
new Example(
"Description of the application",
new Options { Option1 = "Option1", Option2 = 100 })
};
[Option('o', "option1", Required = true, HelpText = "Option1.")]
public string Option1 { get; set; }
[Option('t', "option2", HelpText = "Option2.")]
public int Option2 { get; set; }
}
|
Parse
var options = new Options();
if (CommandLine.Parser.Default.ParseArguments(args, options))
{
if (options.Verbose) { }
var inputDirectory = options.InputDirectory;
if (options.OptionsList != null && options.OptionsList.Contains("mon_option")) { }
}
|
Command line
![]() |
By default options --help and --version are available. |
# option1
-o value
-ovalue
--option1 value
--option1=value
|