1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-24 05:59:55 +08:00

commands: Added HelpText struct to organize different help text fields in Commands

This commit is contained in:
Matt Bell
2014-11-12 01:24:55 -08:00
committed by Juan Batiz-Benet
parent 7116591351
commit 475f3f485b

View File

@ -19,6 +19,21 @@ type Function func(Request) (interface{}, error)
// (or an error on failure) // (or an error on failure)
type Marshaller func(Response) ([]byte, error) type Marshaller func(Response) ([]byte, error)
// HelpText is a set of strings used to generate command help text. The help
// text follows formats similar to man pages, but not exactly the same.
type HelpText struct {
// required
Tagline string // used in <cmd usage>
ShortDescription string // used in DESCRIPTION
// optional - whole section overrides
Usage string // overrides USAGE section
LongDescription string // overrides DESCRIPTION section
Options string // overrides OPTIONS section
Arguments string // overrides ARGUMENTS section
Subcommands string // overrides SUBCOMMANDS section
}
// TODO: check Argument definitions when creating a Command // TODO: check Argument definitions when creating a Command
// (might need to use a Command constructor) // (might need to use a Command constructor)
// * make sure any variadic args are at the end // * make sure any variadic args are at the end
@ -28,8 +43,7 @@ type Marshaller func(Response) ([]byte, error)
// Command is a runnable command, with input arguments and options (flags). // Command is a runnable command, with input arguments and options (flags).
// It can also have Subcommands, to group units of work into sets. // It can also have Subcommands, to group units of work into sets.
type Command struct { type Command struct {
// MAYBE_TODO: move all the text fields into a struct // TODO: remove these fields after porting commands to HelpText struct
// MAYBE_TODO: move these out of command and put them somewhere in commands/cli
Description string Description string
Help string Help string
SubcommandHelp string SubcommandHelp string
@ -40,6 +54,7 @@ type Command struct {
Arguments []Argument Arguments []Argument
Run Function Run Function
Marshallers map[EncodingType]Marshaller Marshallers map[EncodingType]Marshaller
Helptext HelpText
// Type describes the type of the output of the Command's Run Function. // Type describes the type of the output of the Command's Run Function.
// In precise terms, the value of Type is an instance of the return type of // In precise terms, the value of Type is an instance of the return type of