gmich / Gint

A powerful and configurable command line interpreter for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Gint

.Net5 Build

A powerful and configurable command line interpreter for .NET with no dependencies.

Nuget Packages

Package Name Version
Gint.Core Gint.Core
Gint.Terminal Gint.Terminal
Gint.Tables Gint.Tables
Gint.Pipes Gint.Pipes
Gint.Markup Gint.Markup

Quickstart

Markup tldr

install-package Gint.Terminal
using Gint;
using Gint.Terminal;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            var runtime = new CommandRuntime();

            runtime.CommandRegistry.AddCommand(
                commandName: "hello",
                helpCallback: o => o.WithForegroundColor().Cyan().Write("help!"),
                callback: ctx =>
                {
                    var name = ctx.Scope.GetValueOrDefault(key: "--name", @default: "Gint");

                    var txt = ctx.Formatter
                    .WithBackgroundColor().White()
                    .AndForeground().Black()
                    .Write($"Hello {name}!");

                    ctx.Scope.WriteString(txt);

                    return CommandResult.SuccessfulTask;
                })
                .AddVariableOption(
                    argument: "-n",
                    longArgument: "--name",
                    helpCallback: o => o.WithForegroundColor().Cyan().Write("Give a name!"),
                    callback: ctx =>
                    {
                        ctx.Scope.Add("--name", ctx.ExecutingCommand.Variable);
                        return CommandResult.SuccessfulTask;
                    },
                    suggestions: v => new Suggestion[] { "Teresa", "Devin", "Michael", "Maria", "George" });

            var terminal = new CommandTerminal(runtime);

            while (true)
            {
                terminal.WaitForInput();
            }
        }
    }
}

Diagnostics can be toggled with ctrl+shift+d or through the TerminalOptions in the CommandTerminal constructor.

Tables

Simple table

            GintTable
                .WithFirstRowAsHeader()
                    .AddColumn("header1")
                    .AddColumn("header2")
                 .NewRow()
                     .AddColumn("column1")
                     .AddColumn("column2")
                 .NewRow()
                     .AddColumn("column1")
                     .AddColumn("column2")
                 .Build()
                 .RenderToConsole();

For more info on tables, check the wiki.

About

A powerful and configurable command line interpreter for .NET

License:MIT License


Languages

Language:C# 100.0%