UtilityPack.ArgsParser
1.1.5
See the version list below for details.
dotnet add package UtilityPack.ArgsParser --version 1.1.5
NuGet\Install-Package UtilityPack.ArgsParser -Version 1.1.5
<PackageReference Include="UtilityPack.ArgsParser" Version="1.1.5" />
paket add UtilityPack.ArgsParser --version 1.1.5
#r "nuget: UtilityPack.ArgsParser, 1.1.5"
// Install UtilityPack.ArgsParser as a Cake Addin #addin nuget:?package=UtilityPack.ArgsParser&version=1.1.5 // Install UtilityPack.ArgsParser as a Cake Tool #tool nuget:?package=UtilityPack.ArgsParser&version=1.1.5
ArgsParser
Esempio
Esempio di programma da terminale: comando per rimpiazzare una sotto stringa di una stringa
comando : replace
parametri : stringa di base, stringa da rimpiazzare, stringa nuova
opzioni : help, all
Definizione degli argomenti
static void Main(string[] args)
{
//crea una nuova instanza del parser
ArgsParser parser = new();
//definisci un singolo o un array di comandi
parser.AddCommand(new[]
{
new ArgsCommand("replace")
{
ValidParameters = {"replaceParam"},
ValidOptions = {"help", "all"}
}
});
//definisci un set di parametri da attribuire al comando
parser.AddParameterGroup("replaceParam", new[]
{
new ArgsParameter("base_string"),
new ArgsParameter("to_replace"),
new ArgsParameter("new_string"),
});
//definisci le opzioni
parser.AddOption(new[]
{
new ArgsOption("help") { Alias = "h", IsFlag = true},
new ArgsOption("all") { Alias = "a", IsFlag = true}
});
//esegui il parsing partendo dagli argomenti ottenuti dal main
//preferibilmente all'interno di un try-catch per arrestare il processo in caso di errore
try
{
parser.Parse(args);
}
catch (ArgsParseErrorException e)
{
Console.WriteLine(e.StackTrace);
}
}
Esecuzione della logica
//controlla se il comando inserito è 'replace'
if(parser.GetCommand(0) == "replace")
{
//recupera i parametri
string baseString = parser.GetParameter("base_string");
string toReplace = parser.GetParameter("to_replace");
string newString = parser.GetParameter("new_string");
//esecuzione logica del programma
string result = baseString.Replace(toReplace, newString);
Console.WriteLine(result);
}
-----------------------
Componenti
La libreria si compone di 4 elementi:
- ArgsParser: La classe principale per la definizione dei comandi e l'esecuzione del parsing
- ArgsCommand: Classe per definire un nuovo comando
- ArgsOption: Classe per definire una nuova opzione
- ArgsParameterGroup: Classe per definire un nuovo set di parametri
Primo passo è creare un'istanza di ArgsParser all'interno del Main.
ArgsParser parser = new();
Si procede definendo quali saranno i comandi.
È possibile definire anche catene di comandi, in tal caso parametri e opzioni saranno presi per l'ultimo comando inserito nel terminale.
Il metodo parser.AddCommand() accetta sia singole instanze di ArgsCommand che array.
parser.AddCommand(new[]
{
new ArgsCommand("replace")
{
ValidParameters = {"replaceParam"},
ValidOptions = {"help", "all"}
}
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.2.6 | 457 | 7/1/2022 |
1.2.5 | 405 | 7/1/2022 |
1.2.4 | 416 | 6/1/2022 |
1.2.3 | 404 | 6/1/2022 |
1.2.2 | 400 | 5/31/2022 |
1.2.1 | 401 | 5/31/2022 |
1.2.0 | 396 | 5/31/2022 |
1.1.9 | 426 | 5/25/2022 |
1.1.8 | 395 | 5/25/2022 |
1.1.7 | 415 | 5/25/2022 |
1.1.6 | 431 | 3/29/2022 |
1.1.5 | 413 | 3/29/2022 |
1.1.4 | 421 | 3/29/2022 |
1.1.3 | 411 | 3/29/2022 |
1.1.2 | 441 | 3/28/2022 |
1.1.1 | 422 | 3/25/2022 |
1.1.0 | 439 | 2/4/2022 |
1.0.2 | 415 | 1/11/2022 |
1.0.1 | 274 | 12/14/2021 |
1.0.0 | 306 | 11/17/2021 |