UtilityPack.ArgsParser 1.2.6

dotnet add package UtilityPack.ArgsParser --version 1.2.6
NuGet\Install-Package UtilityPack.ArgsParser -Version 1.2.6
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UtilityPack.ArgsParser" Version="1.2.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UtilityPack.ArgsParser --version 1.2.6
#r "nuget: UtilityPack.ArgsParser, 1.2.6"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UtilityPack.ArgsParser as a Cake Addin
#addin nuget:?package=UtilityPack.ArgsParser&version=1.2.6

// Install UtilityPack.ArgsParser as a Cake Tool
#tool nuget:?package=UtilityPack.ArgsParser&version=1.2.6

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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 418 7/1/2022
1.2.5 374 7/1/2022
1.2.4 393 6/1/2022
1.2.3 377 6/1/2022
1.2.2 370 5/31/2022
1.2.1 373 5/31/2022
1.2.0 368 5/31/2022
1.1.9 394 5/25/2022
1.1.8 385 5/25/2022
1.1.7 386 5/25/2022
1.1.6 403 3/29/2022
1.1.5 387 3/29/2022
1.1.4 396 3/29/2022
1.1.3 386 3/29/2022
1.1.2 418 3/28/2022
1.1.1 399 3/25/2022
1.1.0 427 2/4/2022
1.0.2 390 1/11/2022
1.0.1 258 12/14/2021
1.0.0 279 11/17/2021