Skip to content

A C# library to help build console applications (command line interface).

License

Notifications You must be signed in to change notification settings

brunurd/CliHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CliHelper

A C# library to help build console applications (command line interface).

NuGet Version GitHub Release Version License C# Version Framework Version .NETFramework Version


Usage Example

using System;
using CliHelper;

namespace PrintApp
{
    public static class PrintAppMain
    {
        public static void Main(params string[] args)
        {
            var app = new CliApplication("PrintApp");

            var runCommand = app.RegisterCommand("print", 
                "Print something in the console.", Run);

            runCommand.RegisterParameter("message", "Write  message.", 'm');
            runCommand.RegisterFlag("error", "Print in red.", 'e');
        }

        private static void Run(ParameterWithValues[] parameters, Flag[] flags)
        {
            var error = flags.HasFlag("error");

            if (error) {
                Console.ForegroundColor = ConsoleColor.Red;
            }

            var message = parameters.GetParameterByName("message");

            Console.WriteLine(message?.Values[0]);
            Console.ForegroundColor = ConsoleColor.White;
        }
    }
}

After build, do something like:

./PrintApp print --message "Hello!"

# or

./PrintApp print -m "Error!" --error

About

A C# library to help build console applications (command line interface).

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages