climate

package module
v0.0.0-...-6a0a7f8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2023 License: Unlicense Imports: 20 Imported by: 9

README

Climate

Climate "CLI Mate" aims to make creating CLIs in Go easy (and fun!), similar to python-fire.
It's also built on top of Cobra and so comes with "batteries included" (help, shell completion etc.).

Usage

https://github.com/avamsi/climate/blob/45ac60897dee0ea9950a1298e9d754ba454fb1eb/cmd/examples/greet/main.go#L11-L54

$ greet --help

Greet someone.

Usage:
  greet [opts]

Flags:
  -g, --greeting string (default Hello)  greeting to use
  -n, --name     string (default World)  name to greet
  -t, --times    int                     number of times to greet
  -h, --help                             help for greet
  -v, --version                          version for greet
Subcommands

https://github.com/avamsi/climate/blob/45ac60897dee0ea9950a1298e9d754ba454fb1eb/cmd/examples/jj/main.go#L14-L87

$ jj --help

Jujutsu (an experimental VCS).

Usage:
  jj [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  git         Commands for working with the underlying Git repo
  help        Help about any command
  init        Create a new repo in the given directory
  squash      Move changes from a revision into its parent
  util        Infrequently used commands such as for generating shell completions
  version     Display jj's version information

Flags:
  -R, --repository          path  path to the repo to operate on
      --ignore-working-copy       don't snapshot / update the working copy
  -h, --help                      help for jj
  -v, --version                   version for jj

Use "jj [command] --help" for more information about a command.
$ jj git --help

Commands for working with the underlying Git repo.

Usage:
  jj git [command]

Available Commands:
  export      Update the underlying Git repo with changes made in the repo
  remote      Manage Git remotes

Flags:
  -h, --help  help for git

Global Flags:
      --ignore-working-copy       don't snapshot / update the working copy
  -R, --repository          path  path to the repo to operate on

Use "jj git [command] --help" for more information about a command.

Documentation

Overview

Package climate "CLI Mate" provides a set of APIs to autogenerate CLIs from structs/functions with support for nested subcommands, global/local flags, help generation from comments, typo suggestions, shell completion and more.

See https://github.com/avamsi/climate/blob/main/README.md for more details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrExit

func ErrExit(code int, errs ...error) *exitError

ErrExit returns an exitError with the given exit code and errors. exitError is used to indicate that the CLI should exit with the given exit code (as returned by Run and respected by RunAndExit).

func ErrUsage

func ErrUsage(err error) *usageError

ErrUsage returns the given error wrapped in a usageError or nil otherwise. usageError is used to indicate there's something wrong with the user input and that the usage information should be printed along with the error.

func Func

func Func(f any) *funcPlan

Func returns an executable plan for the given function, which must conform to the following signatures (excuse the partial [optional] notation):

func([ctx context.Context], [opts *T], [args []string]) [(err error)]

All of ctx, opts, args and error are optional. If opts is present, T must be a struct (whose fields are used as flags).

func Run

func Run(ctx context.Context, p internal.Plan, mods ...func(*internal.RunOptions)) int

Run executes the given plan and returns the exit code.

func RunAndExit

func RunAndExit(p internal.Plan, mods ...func(*internal.RunOptions))

RunAndExit executes the given plan and exits with the exit code.

func Struct

func Struct[T any](subcommands ...*structPlan) *structPlan

Struct returns an executable plan for the struct given as the type parameter, with its methods* (and "child" structs) as subcommands.

* Only methods with pointer receiver are considered (and they must otherwise conform to the same signatures described in Func).

func WithMetadata

func WithMetadata(b []byte) func(*internal.RunOptions)

WithMetadata returns a modifier that sets the metadata to be used by Run for augmenting the CLI with additional information (for --help etc.).

Types

This section is empty.

Directories

Path Synopsis
cmd
cligen Module
climate Module
examples Module
testing module

Jump to

Keyboard shortcuts

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