broccoli

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2023 License: CC0-1.0 Imports: 9 Imported by: 0

README

GitHub GitHub Workflow Status (event) Go Reference

broccoli

Broccoli: CLI Package for Go

Usage

package main

import (
	"fmt"

	"gopkg.eu.org/broccoli"
)

type Config struct {
	_    struct{} `version:"0.0.1" command:"hello" about:"Test App"`
	Name string   `flag:"name" alias:"n" required:"true" about:"Your name"`

	Sub *SubCommand `subcommand:"sub"`
}

type SubCommand struct {
	_    struct{} `command:"sub" longabout:"Test Sub Command"`
	Name string   `flag:"name" alias:"n" required:"true" about:"Your name"`
}

func main() {
	var cfg Config
	_ = broccoli.BindOSArgs(&cfg)

	if cfg.Sub != nil {
		fmt.Printf("Hello %s from sub command\n", cfg.Sub.Name)
		return
	}

	fmt.Printf("Hello %s from main command\n", cfg.Name)
}
$ hello --help
hello 0.0.1
Test App

Usage:
        hello <COMMAND> [OPTIONS] --name <NAME> [ARGUEMENTS]

Options:
        -n, --name     Your name  (required)
        -h, --help     Print this help message and exit

Commands:
        sub    Test Sub Command

$ hello --name World
Hello World from main command

$ hello sub --name World
Hello World from sub command

Installation

go get -u gopkg.eu.org/broccoli

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHelp = errors.New("broccoli: help")
View Source
var ErrMissingRequiredField = errors.New("broccoli: missing required field")
View Source
var ErrTypeMismatch = errors.New("broccoli: type mismatch")
View Source
var ErrTypeNotSupported = errors.New("broccoli: type not supported")

Functions

func BindOSArgs

func BindOSArgs(dst interface{}) []string

BindOSArgs bind os args to struct

Types

type App

type App struct {
	// contains filtered or unexported fields
}

func Bind

func Bind(dst interface{}, args []string) ([]string, App, error)

func NewApp

func NewApp(v interface{}) (*App, error)

func (*App) Bind

func (a *App) Bind(dst interface{}, args []string) ([]string, App, error)

func (*App) Help

func (a *App) Help() string

func (*App) Schema

func (a *App) Schema() string

Jump to

Keyboard shortcuts

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