cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: BSD-3-Clause Imports: 1 Imported by: 9

Documentation

Overview

Package cli defines the Builder type, which allows one to build a CLI application in a modular way.

var builder Builder
builder.SetName("myapp")

cmd := builder.SetCommand("hello")
cmd.SetDescription("Say hello !")
cmd.SetAction(func(flags Flags) error {
	fmt.Printf("Hello %s!\n", flags.String("dude"))
})

builder.Build().Run(os.Args)

An implementation of the builder is free to provide primitives to create more complex action.

Documentation Last Review: 13.10.2020

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action func(Flags) error

Action is a function that will be executed when a command is invoked.

type Application

type Application interface {
	Run(arguments []string) error
}

Application is the main interface to run the CLI.

type BoolFlag

type BoolFlag struct {
	Name     string
	Usage    string
	Required bool
	Value    bool
}

BoolFlag is a definition of a command flag expected to be parsed as a boolean.

- implements cli.Flag

func (BoolFlag) Flag

func (flag BoolFlag) Flag()

Flag implements cli.Flag.

type Builder

type Builder interface {
	Provider

	// Build returns the application.
	Build() Application
}

Builder is an application builder interface. One can set properties of an application then build it.

type CommandBuilder

type CommandBuilder interface {
	// SetDescription sets the value of the description for this command.
	SetDescription(value string)

	// SetFlags sets the flags for this command.
	SetFlags(...Flag)

	// SetAction sets the action for this command.
	SetAction(Action)

	// SetSubCommand creates a subcommand for this command.
	SetSubCommand(name string) CommandBuilder
}

CommandBuilder is a command builder interface. One can set properties of a specific command like its name and description and what it should do when invoked.

type DurationFlag

type DurationFlag struct {
	Name     string
	Usage    string
	Required bool
	Value    time.Duration
}

DurationFlag is a definition of a command flag expected to be parsed as a duration.

- implements cli.Flag

func (DurationFlag) Flag

func (flag DurationFlag) Flag()

Flag implements cli.Flag.

type Flag

type Flag interface {
	Flag()
}

Flag is an identifier for the definition of the flags.

type Flags

type Flags interface {
	String(name string) string

	StringSlice(name string) []string

	Duration(name string) time.Duration

	Path(name string) string

	Int(name string) int

	Bool(name string) bool
}

Flags provides the primitives to an action to read the flags.

type Initializer

type Initializer interface {
	// SetCommands if the function called by the builder to add the modules'
	// commands. The modules implement this function and use the provided
	// provider to create its specific commands.
	SetCommands(Provider)
}

Initializer defines a primitive for modules to add their commands. A cli will gather all the initializers from each desired modules and call the SetCommands for each of them.

type IntFlag

type IntFlag struct {
	Name     string
	Usage    string
	Required bool
	Value    int
}

IntFlag is a definition of a command flag expected to be parsed as a integer.

- implements cli.Flag

func (IntFlag) Flag

func (flag IntFlag) Flag()

Flag implements cli.Flag.

type Provider

type Provider interface {
	// SetCommand creates a new command with the given name and returns its
	// builder.
	SetCommand(name string) CommandBuilder
}

Provider defines a primitive for modules to provide their commands

type StringFlag

type StringFlag struct {
	Name     string
	Usage    string
	Required bool
	Value    string
}

StringFlag is a definition of a command flag expected to be parsed as a string.

- implements cli.Flag

func (StringFlag) Flag

func (flag StringFlag) Flag()

Flag implements cli.Flag.

type StringSliceFlag

type StringSliceFlag struct {
	Name     string
	Usage    string
	Required bool
	Value    []string
}

StringSliceFlag is a definition of a command flag expected to tbe parsed as a slice of strings.

- implements cli.Flag

func (StringSliceFlag) Flag

func (flag StringSliceFlag) Flag()

Flag implements cli.Flag.

Directories

Path Synopsis
Package main provides a cli for crypto operations like generating keys or displaying specific key formats.
Package main provides a cli for crypto operations like generating keys or displaying specific key formats.
Package node defines the Builder type, which builds an CLI application to controle a node.
Package node defines the Builder type, which builds an CLI application to controle a node.
memcoin
Package main implements a ledger based on in-memory components.
Package main implements a ledger based on in-memory components.
Package ucli provides a cli builder implementation based on the urfave/cli library.
Package ucli provides a cli builder implementation based on the urfave/cli library.

Jump to

Keyboard shortcuts

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