package cli
import "go.dedis.ch/dela/cli"
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 ¶
- type Action
- type Application
- type BoolFlag
- type Builder
- type CommandBuilder
- type DurationFlag
- type Flag
- type Flags
- type Initializer
- type IntFlag
- type Provider
- type StringFlag
- type StringSliceFlag
Types ¶
type Action ¶
Action is a function that will be executed when a command is invoked.
type Application ¶
Application is the main interface to run the CLI.
type BoolFlag ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.
Source Files ¶
cli.go flag.go
Directories ¶
Path | Synopsis |
---|---|
cli/crypto | Package main provides a cli for crypto operations like generating keys or displaying specific key formats. |
cli/node | Package node defines the Builder type, which builds an CLI application to controle a node. |
cli/node/memcoin | Package main implements a ledger based on in-memory components. |
cli/ucli | Package ucli provides a cli builder implementation based on the urfave/cli library. |
- Version
- v0.1.0 (latest)
- Published
- Apr 10, 2024
- Platform
- linux/amd64
- Imports
- 1 packages
- Last checked
- 1 month ago –
Tools for package owners.