github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/protocol/command.go (about) 1 /* For license and copyright information please see the LEGAL file in the code repository */ 2 3 package protocol 4 5 // Command is the interface that must implement by any struct to be a command service 6 type Command interface { 7 // Init(parent Command, subCommands ...Command) 8 9 Name() string // e.g. init 10 // These are not suggested to the user in the shell completion, 11 // but accepted if entered manually. 12 Aliases() []string // e.g. []string{"initialize", "initialise", "create"} 13 14 // UsageLine is the one-line usage message. 15 // Recommended syntax is as follow: 16 // [ ] identifies an optional argument. Arguments that are not enclosed in brackets are required. 17 // ... indicates that you can specify multiple values for the previous argument. 18 // | indicates mutually exclusive information. You can use the argument to the left of the separator or the 19 // argument to the right of the separator. You cannot use both arguments in a single use of the command. 20 // { } delimits a set of mutually exclusive arguments when one of the arguments is required. If the arguments are 21 // optional, they are enclosed in brackets ([ ]). 22 // Example: '<app> add [-F file | -D dir]... [-f format] profile' 23 UsageLine() string 24 25 // Runnable reports whether the command can be run; otherwise it is a documentation pseudo-command 26 Runnable() bool 27 28 // parent is a parent command for this command. 29 Parent() Command 30 // SubCommand return a sub command by its name or alias that must use intelligent suggestion 31 SubCommand(name string) Command 32 // Commands lists the available commands and help topics. 33 // The order here is the order in which they are printed by 'go help'. 34 // Note that subcommands are in general best avoided. 35 SubCommands() []Command 36 37 CommandHandler 38 ServiceDetails 39 } 40 41 // CommandHandler is any object to be CLI (command-line interface) service handler. 42 type CommandHandler interface { 43 // ServeCLA or serve by command-line arguments might block the caller 44 // Arguments list not include the command name. 45 ServeCLA(arguments []string) (err Error) 46 47 // read and write to os.Stdin, os.Stdout, and os.Stderr files 48 // ServeCLI() (err Error) 49 } 50 51 type CommandLineArguments interface { 52 FromCLA(arguments []string) (remaining []string, err Error) 53 ToCLA() (arguments []string, err Error) 54 }