GithubHelp home page GithubHelp logo

younescheikh / cliargs.net Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 1.67 MB

Command Line Interface Arguments parser & C# API

License: Other

C# 100.00%
cli args command-line-tool csharp dotnet dotnet-core

cliargs.net's Introduction

Cliargs.NET

Command Line Interface Arguments parser for dotnet

NuGet Badge License
.NET Test Coverage
image Build history

Knowledge base

More examples and documentation is on Cliargs.NET Knowledge base


Cliargs.NET is a dotnet library helps you to parse and use the Command Line Interface arguments in easy way.

The main goal of Cliargs.NET is to help C# developers reduce their programming time without dealing with all validations and casting of the user input.

Cliargs.NET makes all for you, all you have to do is write your Setup configuration in order to configure the Arguments container, then, from key and values parsing, to validation is automatically done on app startup.

Install

Package Manager

Install-Package Cliargs.NET

Dotnet CLI

dotnet add package Cliargs.NET

Quick comparison

In this example, you see the difference between managing the command line arguments by yourself, or by Cliargs.NET, for an application with two arguments:

Argument         type key short key Optional
User Name string --name -n no
User age uint --age -a yes

The objective is to display the following message in a console app:

Dear {user name}, you're {user age} years old!

Example of old school way: 😔

👉 Example on gist 👈

New way with Cliargs.NET 🤩

Create your Setup class and implement the Configure method to create your app arguments:

public class CliArgsSetup : ICliArgsSetup
{
    public void Configure(ICliArgsContainer container)
    {
        var nameArg = CliArg.New<string>("name")
            .AsRequired()
            .WithShortName("n");

        var ageArg = CliArg.New<uint>("age")
            .AsOptional()
            .WithShortName("a");

        container.Register(nameArg);
        container.Register(ageArg);
    }
}

Initialize the AppCliArgs instance by calling Initialize method at the begining of your app main method:

AppCliArgs.Initialize<CliArgsSetup>(new CustomFormat());

The finally start using the arguments values

var name = AppCliArgs.GetArgValue<string>("name");
if (AppCliArgs.IsSet("age"))
{
    var age = AppCliArgs.GetArgValue<uint>("age");
    Console.WriteLine($"Dear {name}, you're {age} years old.");
}
else
{
    Console.WriteLine($"Dear {name}, we don't know your age!");
}

cliargs.net's People

Contributors

younescheikh avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.