G4.Abstraction.Cli
2024.11.14.73
See the version list below for details.
dotnet add package G4.Abstraction.Cli --version 2024.11.14.73
NuGet\Install-Package G4.Abstraction.Cli -Version 2024.11.14.73
<PackageReference Include="G4.Abstraction.Cli" Version="2024.11.14.73" />
paket add G4.Abstraction.Cli --version 2024.11.14.73
#r "nuget: G4.Abstraction.Cli, 2024.11.14.73"
// Install G4.Abstraction.Cli as a Cake Addin #addin nuget:?package=G4.Abstraction.Cli&version=2024.11.14.73 // Install G4.Abstraction.Cli as a Cake Tool #tool nuget:?package=G4.Abstraction.Cli&version=2024.11.14.73
G4.Abstraction.Cli
G4.Abstraction.Cli is a command-line interface (CLI) factory that provides tools for generating CLI structures and patterns. This library allows developers to parse and validate CLI input, extract argument keys and values, handle arrays of values, and process nested CLI expressions. It simplifies command-line processing for applications that use complex CLI arguments or templates.
Installation
To install G4.Abstraction.Cli, add the NuGet package:
dotnet add package G4.Abstraction.Cli
Features
- CLI Template Parsing: Extracts CLI templates from larger strings using regular expression patterns.
- Argument Extraction: Extracts individual CLI arguments, keys, and values.
- Array Support: Supports multiple values for the same key, returning a serialized JSON array of all values under that key.
- Nested Expression Handling: Identifies and encodes nested CLI expressions within the template.
- Compliance Check: Confirms the validity of a CLI against a specified pattern.
- Dictionary Conversion: Converts CLI strings into a dictionary of key-value pairs for easy access.
Usage
1. CLI Validation Example
To validate a CLI string against the factory's CLI template pattern, use the ConfirmCli
method. The expected format for CLI input is {{$ --key:value --anotherKey:value}}
.
using G4.Abstraction.Cli;
var cliFactory = new CliFactory();
bool isValid = cliFactory.ConfirmCli("{{$ --key:value --anotherKey:value}}");
if (isValid)
{
Console.WriteLine("The CLI is valid according to the template pattern.");
}
else
{
Console.WriteLine("The CLI is not valid.");
}
2. Convert CLI to Dictionary
You can convert a CLI string into a dictionary of key-value pairs using the ConvertToDictionary
method. This is useful for structured access to CLI arguments.
using G4.Abstraction.Cli;
var cliFactory = new CliFactory();
var cli = "{{$ --name:JohnDoe --age:30 --location:USA}}";
// Convert the CLI string to a dictionary of arguments
var arguments = cliFactory.ConvertToDictionary(cli);
foreach (var arg in arguments)
{
Console.WriteLine($"{arg.Key}: {arg.Value}");
}
This example would produce output like:
Name: JohnDoe
Age: 30
Location: USA
3. Array Support Example
The CliFactory
supports arrays by allowing multiple entries with the same key. When multiple values are specified for a key, ConvertToDictionary
will return a serialized JSON array containing all values under that key.
using G4.Abstraction.Cli;
var cliFactory = new CliFactory();
var cli = "{{$ --names:foo --names:bar --names:some other name}}";
// Convert the CLI string to a dictionary of arguments
var arguments = cliFactory.ConvertToDictionary(cli);
foreach (var arg in arguments)
{
Console.WriteLine($"{arg.Key}: {arg.Value}");
}
This example would produce output like:
Names: ["foo", "bar", "some other name"]
The ConvertToDictionary
method serializes all values under the same key as a JSON array string, making it easy to handle lists of values in the CLI input as a single serialized JSON array.
4. Parsing Nested Expressions
The ConvertToDictionary
method automatically handles nested CLI expressions within the {{$ }}
syntax. For example, nested structures within the CLI string will be mapped correctly in the output dictionary.
Patterns Used
The CliFactory
uses several regular expression patterns for extracting and processing CLI arguments:
- CLI Template Pattern: Used to isolate the CLI template from larger strings.
- Argument Pattern: Extracts individual CLI arguments.
- Key Pattern: Extracts keys from CLI arguments.
- Value Pattern: Extracts values from CLI arguments.
- Nested Expression Pattern: Detects and encodes nested CLI expressions for easy processing.
License
This library is released under the Apache License 2.0.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. |
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on G4.Abstraction.Cli:
Package | Downloads |
---|---|
G4.Extensions
The G4.Extensions namespace provides a versatile set of extension methods designed to enhance functionality across a variety of types, including collections and dictionaries. These extensions facilitate common operations such as converting dictionaries to XML representations, adding items to collections, and retrieving values from dictionaries with default or specified default values. |
|
G4.Plugins
The G4™ Framework Plugins Core package provides essential infrastructure for building extensible plugins within the G4™ automation engine. Developers can create diverse plugins that seamlessly integrate with G4's core functionality. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2024.11.14.75 | 196 | 11/14/2024 |
2024.11.14.74 | 98 | 11/14/2024 |
2024.11.14.73 | 102 | 11/14/2024 |
2024.11.14.72 | 98 | 11/14/2024 |
2024.11.13.70 | 110 | 11/13/2024 |
2024.11.12.63 | 116 | 11/12/2024 |