Documentation ¶
Overview ¶
Example (FormatTable) ¶
package main import ( "fmt" "github.com/internet-computer/oko/internal/cmd" ) func main() { fmt.Println(cmd.FormatTable([][]string{ {"_", "__", "___"}, {"a", "b", "c"}, {"____", "d", "_", "e"}, }, " | ", "\n", "| ")) }
Output: | _ | __ | ___ | a | b | c | ____ | d | _ | e
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AskForConfirmation ¶
func FormatTable ¶
Types ¶
type Command ¶
type Command struct { // The name of the command. Name string // Aliases of the name. // e.g. version -> v Aliases []string // A summary explaining the function of the command. Summary string // A longer description of the command. Description string // A list of sub commands. Commands []Command // A list of arguments. Args []string // Options of the command. // e.g. --all, etc. Options []Option // The method corresponding with a list of arguments. Method func(args []string, options map[string]string) error }
A command with either sub-commands or a list of arguments.
func (Command) Help ¶
func (c Command) Help()
Example ¶
package main import ( "fmt" "github.com/internet-computer/oko/internal/cmd" ) var ( s = cmd.Command{ Name: "sub", Args: []string{"c"}, Options: []cmd.Option{ {"all", "", false}, {"v", "", true}, }, Method: func(args []string, options map[string]string) error { fmt.Println(args, options) return nil }, } c = cmd.Command{ Name: "test", Aliases: []string{"t"}, Commands: []cmd.Command{s}, } ) func main() { c.Help() }
Output: Usage: test <command> Commands: <sub>
Example (Sub) ¶
package main import ( "fmt" "github.com/internet-computer/oko/internal/cmd" ) var ( s = cmd.Command{ Name: "sub", Args: []string{"c"}, Options: []cmd.Option{ {"all", "", false}, {"v", "", true}, }, Method: func(args []string, options map[string]string) error { fmt.Println(args, options) return nil }, } c = cmd.Command{ Name: "test", Aliases: []string{"t"}, Commands: []cmd.Command{s}, } ) func main() { _ = c.Call("sub", "help") }
Output: Usage: sub <c> Optional arguments: all v <value>
Example (SubC) ¶
package main import ( "fmt" "github.com/internet-computer/oko/internal/cmd" ) var ( s = cmd.Command{ Name: "sub", Args: []string{"c"}, Options: []cmd.Option{ {"all", "", false}, {"v", "", true}, }, Method: func(args []string, options map[string]string) error { fmt.Println(args, options) return nil }, } c = cmd.Command{ Name: "test", Aliases: []string{"t"}, Commands: []cmd.Command{s}, } ) func main() { _ = c.Call("sub", "c") _ = c.Call("sub", "--all", "c") _ = c.Call("sub", "c", "--all") _ = c.Call("sub", "c", "--v=0") _ = c.Call("sub", "--v", "0", "c") }
Output: [c] map[] [c] map[all:] [c] map[all:] [c] map[v:0] [c] map[v:0]
type CommandNotFoundError ¶
type CommandNotFoundError struct{}
func NewCommandNotFoundError ¶
func NewCommandNotFoundError() *CommandNotFoundError
func (CommandNotFoundError) Error ¶
func (e CommandNotFoundError) Error() string
type InvalidArgumentsError ¶
type InvalidArgumentsError struct {
Message string
}
func NewInvalidArgumentsError ¶
func NewInvalidArgumentsError(msg string) *InvalidArgumentsError
func (InvalidArgumentsError) Error ¶
func (e InvalidArgumentsError) Error() string
Click to show internal directories.
Click to hide internal directories.