go-console

module
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2019 License: MIT

README

The Go console component

CircleCI GolangCI Go Report Card

The Console component eases the creation of beautiful and testable command line interfaces.

GoConsole component allows you to create command-line commands. Your console commands can be used for any recurring task, such as cronjobs, imports, or other batch jobs. Command arguments and options follow the docopt standard. This library provide several helper for styling of the command's output.

GoConsole is a lightweight equivalent in Go to the Console Component of Symfony PHP framework.

Creating a Console Application

package main

import (
    "fmt"
    "github.com/DrSmithFr/go-console/pkg/input/argument"
    "github.com/DrSmithFr/go-console/pkg/input/option"
    "github.com/DrSmithFr/go-console/pkg/style"
)

func main() {
    io := style.
        NewConsoleStyler().
        AddInputArgument(
            argument.
                New("name", argument.REQUIRED),
        ).
        AddInputOption(
            option.
                New("foo", option.NONE).
                SetShortcut("f"),
        ).
        ParseInput().
        ValidateInput()

    //
    // Do what you want with console and args !
    //

    io.Title("Starting console")

    io.TextArray([]string{
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
        "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
    })

    io.Note(
        fmt.Sprintf(
            "name argument value '%s'",
            io.GetInput().GetArgument("name"),
        ),
    )

    if option.DEFINED == io.GetInput().GetOption("foo") {
        io.Success("foo option is set")
    } else {
        io.Error("foo option is set")
    }
}

Learn more

Directories

Path Synopsis
examples
command command
formatter command
output command
style command
pkg
tests

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL