babycli

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

babycli

Go Reference License Build

babycli is a modern CLI arguments parser for Go.

Requirements

The minimum Go version is go1.23.

Getting Started

The babycli package can be added to a project with go get.

go get cattlecloud.net/go/babycli@latest
import "cattlecloud.net/go/babycli"
Influence

This library was made after many projects of using urfave/cli, one of the better command line parser libraries for Go. babycli models itself after this library but with a cleaner, more robust implementation under the hood. Credit of inspiration belongs to the authors.

Experimental

(!) Please note this library is still experimental and being worked on, with breaking changes being very likely.

License

The cattlecloud.net/go/babycli module is open source under the BSD license.

Documentation

Overview

Package babycli is a library for declrative parsing of command line arguments, including support for sub-commands, command aliases, long and short flag names, repeated flags, and custom help messages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arguments

func Arguments() []string

Types

type Code

type Code = int
const (
	Success   Code = 0
	Failure   Code = 1
	Usability Code = math.MaxInt
)

type Component

type Component struct {
	Name string

	Help string

	Description string

	Components Components

	Function Func

	Flags Flags
	// contains filtered or unexported fields
}

func (*Component) Arguments

func (c *Component) Arguments() []string

func (*Component) Context

func (c *Component) Context() context.Context

func (*Component) GetBool

func (c *Component) GetBool(flag string) bool

func (*Component) GetBools

func (c *Component) GetBools(flag string) []bool

func (*Component) GetDuration

func (c *Component) GetDuration(flag string) time.Duration

func (*Component) GetDurations

func (c *Component) GetDurations(flag string) []time.Duration

func (*Component) GetInt

func (c *Component) GetInt(flag string) int

func (*Component) GetInts

func (c *Component) GetInts(flag string) []int

func (*Component) GetString

func (c *Component) GetString(flag string) string

func (*Component) GetStrings

func (c *Component) GetStrings(flag string) []string

func (*Component) HasBool

func (c *Component) HasBool(flag string) bool

func (*Component) HasDuration

func (c *Component) HasDuration(flag string) bool

func (*Component) HasInt

func (c *Component) HasInt(flag string) bool

func (*Component) HasString

func (c *Component) HasString(flag string) bool

func (*Component) Leaf

func (c *Component) Leaf() bool

func (*Component) Nargs

func (c *Component) Nargs() int

type Components

type Components []*Component

func (Components) Contains

func (cs Components) Contains(name string) bool

func (Components) Get

func (cs Components) Get(name string) *Component

type Configuration

type Configuration struct {
	Arguments []string
	Top       *Component
	Globals   Flags
	Version   string
	Output    io.Writer
	Context   context.Context
}

type Default

type Default struct {
	Value any
	Show  bool
}

type Flag

type Flag struct {
	Type    FlagType
	Require bool
	Repeats bool
	Long    string
	Short   string
	Help    string
	Default *Default
}

func (*Flag) Identity

func (f *Flag) Identity() string

func (*Flag) Is

func (f *Flag) Is(name string) bool

type FlagType

type FlagType uint8
const (
	StringFlag FlagType = iota
	IntFlag
	BooleanFlag
	DurationFlag
)

func (FlagType) String

func (t FlagType) String() string

type Flags

type Flags []*Flag

func (Flags) Contains

func (fs Flags) Contains(name string) bool

func (Flags) Get

func (fs Flags) Get(name string) *Flag

type Func

type Func func(*Component) Code

type Runnable

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

func New

func New(c *Configuration) *Runnable

func (*Runnable) Run

func (r *Runnable) Run() (c Code)

Jump to

Keyboard shortcuts

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