go-command

command module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2025 License: MIT Imports: 5 Imported by: 0

README

go-command GoDoc

The go-command module provides several types for managing multiple commands within the same command-line application. This approach to software architecture allows a single application to perform many tasks while ensuring the various commands stay modular and respect the separation of concerns principal.

Usage

The module consists mainly of four packages:

  • command: this packages defines multiple types for defining, creating, and running commands
  • command/sample: this package defines sample commands useful for learning how the module works
  • style: this package provides semantic types and methods for changing the style (mode and colour) of console output
  • util: this packages provides simple helper functions for a verity of general use cases

The following main definition demonstrates the basic usage of the module:

func main() {
	ls := flag.Bool("ls", false, "list all commands")
	flag.Parse()

	runner := command.NewRunner(
		sample.NewHelloCommand(),
		command.NewConfigCommand[sample.SampleConfig](),
	)

	if *ls || len(os.Args) < 2 {
		runner.ListCommands()
		return
	}

	if err := runner.RunCommand(os.Args[1], os.Args[2:]); err != nil {
		style.BoldError.Print("ERROR: ")
		fmt.Println(err)
	}
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Provides several common helper functions
Provides several common helper functions
Provides several types for managing multiple commands within a single application.
Provides several types for managing multiple commands within a single application.
sample
Provides sample commands used to demonstrate the command package.
Provides sample commands used to demonstrate the command package.
Provides semantic types and functions for styling terminal outputs using ANSI escape sequences.
Provides semantic types and functions for styling terminal outputs using ANSI escape sequences.

Jump to

Keyboard shortcuts

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