All Projects → natemcmaster → Commandlineutils

natemcmaster / Commandlineutils

Licence: apache-2.0
Command line parsing and utilities for .NET

Programming Languages

C#
18002 projects
powershell
5483 projects

Projects that are alternatives of or similar to Commandlineutils

Commanddotnet
A modern framework for building modern CLI apps
Stars: ✭ 251 (-85.91%)
Mutual labels:  command-line, dotnet-core
Command Line Api
Command line parsing, invocation, and rendering of terminal output.
Stars: ✭ 2,418 (+35.69%)
Mutual labels:  command-line, dotnet-core
Commandline
The best C# command line parser that brings standardized *nix getopt style, for .NET. Includes F# support
Stars: ✭ 3,209 (+80.08%)
Mutual labels:  command-line, dotnet-core
Sharprompt
Interactive command line interface toolkit for C#
Stars: ✭ 197 (-88.95%)
Mutual labels:  command-line, dotnet-core
Cocona
Micro-framework for .NET Core console application. Cocona makes it easy and fast to build console applications on .NET Core.
Stars: ✭ 398 (-77.67%)
Mutual labels:  command-line, dotnet-core
Dotnetbook
.NET Platform Architecture book (English, Chinese, Russian)
Stars: ✭ 1,763 (-1.07%)
Mutual labels:  dotnet-core
Urban
Command line tool and API for the Urban Dictionary
Stars: ✭ 126 (-92.93%)
Mutual labels:  command-line
Darker
The query-side counterpart of Brighter
Stars: ✭ 124 (-93.04%)
Mutual labels:  dotnet-core
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-93.21%)
Mutual labels:  dotnet-core
Sty
String styling for your terminal.
Stars: ✭ 129 (-92.76%)
Mutual labels:  command-line
Aaframework
AA.Framework is built on the popular open source class library of NET Core
Stars: ✭ 128 (-92.82%)
Mutual labels:  dotnet-core
Dynein
DynamoDB CLI written in Rust.
Stars: ✭ 126 (-92.93%)
Mutual labels:  command-line
Clrcli
CLRCLI is an event-driven library for building line-art user interfaces in C#/.Net command-line applications.
Stars: ✭ 124 (-93.04%)
Mutual labels:  command-line
Desktoppr
Simple command line tool to set the desktop picture on macOS
Stars: ✭ 127 (-92.87%)
Mutual labels:  command-line
Giraffe
Giraffe is an F# micro web framework for building rich web applications. It has been heavily inspired and is similar to Suave, but has been specifically designed with ASP.NET Core in mind and can be plugged into the ASP.NET Core pipeline via middleware. Giraffe applications are composed of so called HttpHandler functions which can be thought of a mixture of Suave's WebParts and ASP.NET Core's middleware.
Stars: ✭ 1,703 (-4.43%)
Mutual labels:  dotnet-core
Check It Out
A command line interface for Git Checkout. See branches available for checkout.
Stars: ✭ 127 (-92.87%)
Mutual labels:  command-line
Flow Cli
The Flow CLI is a command-line interface that provides useful utilities for building Flow applications
Stars: ✭ 123 (-93.1%)
Mutual labels:  command-line
Couchimport
CouchDB import tool to allow data to be bulk inserted
Stars: ✭ 125 (-92.99%)
Mutual labels:  command-line
Downloader
Fast and reliable multipart downloader with asynchronous progress events for .NET applications.
Stars: ✭ 128 (-92.82%)
Mutual labels:  dotnet-core
Nnn
n³ The unorthodox terminal file manager
Stars: ✭ 13,138 (+637.26%)
Mutual labels:  command-line

CommandLineUtils

Build Status Code Coverage NuGet NuGet Downloads

This project helps you create command line applications using .NET. It simplifies parsing arguments provided on the command line, validating user inputs, and generating help text.

The roadmap for this project is pinned to the top of the issue list.

Usage

See documentation for API reference, samples, and tutorials. See also docs/samples/ for more examples, such as:

Installing the library

This project is available as a NuGet package.

$ dotnet add package McMaster.Extensions.CommandLineUtils

Code

CommandLineApplication is the main entry point for most console apps parsing. There are two primary ways to use this API, using the builder pattern and attributes.

Attribute API

using System;
using McMaster.Extensions.CommandLineUtils;

public class Program
{
    public static int Main(string[] args)
        => CommandLineApplication.Execute<Program>(args);

    [Option(Description = "The subject")]
    public string Subject { get; } = "world";

    [Option(ShortName = "n")]
    public int Count { get; } = 1;

    private void OnExecute()
    {
        for (var i = 0; i < Count; i++)
        {
            Console.WriteLine($"Hello {Subject}!");
        }
    }
}

Builder API

using System;
using McMaster.Extensions.CommandLineUtils;

var app = new CommandLineApplication();

app.HelpOption();

var subject = app.Option("-s|--subject <SUBJECT>", "The subject", CommandOptionType.SingleValue);
subject.DefaultValue = "world";

var repeat = app.Option<int>("-n|--count <N>", "Repeat", CommandOptionType.SingleValue);
repeat.DefaultValue = 1;

app.OnExecute(() =>
{
    for (var i = 0; i < repeat.ParsedValue; i++)
    {
        Console.WriteLine($"Hello {subject.Value()}!");
    }
});

return app.Execute(args);

Utilities

The library also includes other utilities for interaction with the console. These include:

  • ArgumentEscaper - use to escape arguments when starting a new command line process.
     var args = new [] { "Arg1", "arg with space", "args ' with \" quotes" };
     Process.Start("echo", ArgumentEscaper.EscapeAndConcatenate(args));
  • Prompt - for getting feedback from users with a default answer. A few examples:
    // allows y/n responses, will return false by default in this case.
    // You may optionally change the prompt foreground and background color for
    // the message.
    Prompt.GetYesNo("Do you want to proceed?", false);
    
    // masks input as '*'
    Prompt.GetPassword("Password: ");
  • DotNetExe - finds the path to the dotnet.exe file used to start a .NET Core process
    Process.Start(DotNetExe.FullPathOrDefault(), "run");

And more! See the documentation for more API, such as IConsole, IReporter, and others.

Project origin and status

This is a fork of Microsoft.Extensions.CommandLineUtils, which is no longer under active development. This fork, on the other hand, will continue to make improvements, release updates, and accept contributions. It is currently maintained by @natemcmaster.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].