Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/ cli Public

A fast, zero-dependency Go CLI framework with automatic flag inheritance, type-safe arguments, lifecycle hooks, context support, and full shell completion. Build fluent, powerful command hierarchies with minimal code. Clean API, rich docs, and production-ready features.

License

Notifications You must be signed in to change notification settings

nyxstack/cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

nyxstack/cli

A simple, powerful CLI framework for Go with automatic flag inheritance and type-safe arguments.

Go Version License Test Coverage

Features

  • Automatic Flag Inheritance - Parent flags available to all child commands
  • Type-Safe Arguments - Automatic type conversion for function parameters
  • Lifecycle Hooks - PreRun, PostRun, PersistentPreRun, PersistentPostRun
  • Context Support - Built-in context.Context for cancellation and timeouts
  • Shell Completion - Bash, Zsh, Fish, and PowerShell
  • Fluent API - Chainable interface for building CLI apps
  • Zero Dependencies - Only depends on github.com/nyxstack/color

Installation

go get github.com/nyxstack/cli

Documentation

πŸ“– Full Documentation - Comprehensive guides and API reference

Quick Start

package main
import (
 "context"
 "fmt"
 "github.com/nyxstack/cli"
)
func main() {
 var verbose bool
 
 app := cli.Root("myapp").
 Description("My awesome CLI application").
 Flag(&verbose, "verbose", "v", false, "Enable verbose output").
 Action(func(ctx context.Context, cmd *cli.Command) error {
 if verbose {
 fmt.Println("Verbose mode enabled")
 }
 fmt.Println("Hello from myapp!")
 return nil
 })
 
 if err := app.Execute(); err != nil {
 fmt.Fprintln(os.Stderr, "Error:", err)
 os.Exit(1)
 }
}

Usage:

myapp # Hello from myapp!
myapp --verbose=true # Verbose mode enabled + Hello from myapp!
myapp -v # Same as above
myapp --help # Shows automatic help

See the Quick Start Guide for more examples.

Why nyxstack/cli?

Automatic Flag Inheritance

var verbose bool
root.Flag(&verbose, "verbose", "v", false, "Verbose output")
deploy := cli.Cmd("deploy")
root.AddCommand(deploy)
// --verbose automatically available on deploy command!
// Works: myapp --verbose=true deploy
// Works: myapp deploy --verbose=true

Type-Safe Arguments

cli.Cmd("deploy").
 Arg("environment", "Target environment", true).
 Arg("replicas", "Number of replicas", true).
 Action(func(ctx context.Context, cmd *cli.Command, env string, replicas int) error {
 // env is string, replicas is int - automatic conversion!
 fmt.Printf("Deploying to %s with %d replicas\n", env, replicas)
 return nil
 })

Context Support

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
app.ExecuteContext(ctx) // Automatic timeout handling

Examples

Comprehensive examples in examples/ directory:

Contributing

Contributions welcome! Please ensure:

  1. All tests pass: go test -v
  2. Coverage maintained: go test -cover
  3. Code formatted: go fmt ./...

License

MIT License - see LICENSE file.

About

A fast, zero-dependency Go CLI framework with automatic flag inheritance, type-safe arguments, lifecycle hooks, context support, and full shell completion. Build fluent, powerful command hierarchies with minimal code. Clean API, rich docs, and production-ready features.

Topics

Resources

License

Stars

Watchers

Forks

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /