Skip to content
GoConsole: the golang component that eases the creation of beautiful command line interfaces.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
docs
examples
pkg
tests
.gitignore
CHANGELOG.md
LICENSE
README.md

README.md

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()

	// enable stylish errors
	defer io.HandleRuntimeException()

	//
	// 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")
	}

	panic("this error will be stylish!")
}

Learn more

You can’t perform that action at this time.