Documentation
¶
Overview ¶
Package cli contains helpers used by transport-specific command-line client generators for parsing the command-line flags to identify the service and the method to make a request along with the request payload to be sent.
Index ¶
- func ClientCLIFiles(genpkg string, root *expr.RootExpr) map[string]*codegen.File
- func FieldLoadCode(arg *http.InitArgData, fullName string, payload expr.DataType) (string, bool)
- func Generate(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
- func PayloadBuilderSection(buildFunction *BuildFunctionData) *codegen.SectionTemplate
- type BuildFunctionData
- type CommandData
- type FieldData
- type ParamData
- type PayloadInitData
- type SubcommandData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClientCLIFiles ¶
func ClientCLIFiles(genpkg string, root *expr.RootExpr) map[string]*codegen.File
ClientCLIFiles returns the client HTTP CLI support files mapped according to their full path.
func FieldLoadCode ¶
func FieldLoadCode(arg *http.InitArgData, fullName string, payload expr.DataType) (string, bool)
FieldLoadCode returns the code used in the build payload function that initializes one of the payload object fields. It returns the initialization code and a boolean indicating whether the code requires an "err" variable.
func Generate ¶
func Generate(genpkg string, roots []eval.Root, files []*codegen.File) ([]*codegen.File, error)
Generate produces the fuseml modified CLI code files
func PayloadBuilderSection ¶
func PayloadBuilderSection(buildFunction *BuildFunctionData) *codegen.SectionTemplate
PayloadBuilderSection builds the section template that can be used to generate the payload builder code.
Types ¶
type BuildFunctionData ¶
type BuildFunctionData struct {
// Name is the build payload function name.
Name string
// Description describes the payload function.
Description string
// Params is the list of build function parameters names.
Params []*ParamData
// ServiceName is the name of the service.
ServiceName string
// MethodName is the name of the method.
MethodName string
// ResultType is the fully qualified payload type name.
ResultType string
// Fields describes the payload fields.
Fields []*FieldData
// PayloadInit contains the data needed to render the function
// body.
PayloadInit *PayloadInitData
// CheckErr is true if the payload initialization code requires an
// "err error" variable that must be checked.
CheckErr bool
}
BuildFunctionData contains the data needed to generate a constructor function that builds a service method payload type from values extracted from command line flags.
type CommandData ¶
type CommandData struct {
// Name of command e.g. "cellar-storage"
Name string
// VarName is the name of the command variable e.g.
// "cellarStorage"
VarName string
// Description is the help text.
Description string
// Subcommands is the list of endpoint commands.
Subcommands []*SubcommandData
// PkgName is the service HTTP client package import name,
// e.g. "storagec".
PkgName string
}
CommandData contains the data needed to render a command.
func BuildCommandData ¶
func BuildCommandData(data *service.Data) *CommandData
BuildCommandData builds the data needed by CLI code generators to render the parsing of the service command.
type FieldData ¶
type FieldData struct {
// Name is the field name, e.g. "Vintage"
Name string
// VarName is the name of the local variable holding the field
// value, e.g. "vintage"
VarName string
// TypeRef is the reference to the type.
TypeRef string
// Init is the code initializing the variable.
Init string
}
FieldData contains the data needed to generate the code that initializes a field in the method payload type.
type ParamData ¶ added in v0.1.0
type ParamData struct {
// Name is the name of the parameter.
Name string
// TypeName is the parameter data type.
TypeName string
}
ParamData contains the data needed to generate the parameters accepted by the payload function.
type PayloadInitData ¶
type PayloadInitData struct {
// Code is the payload initialization code.
Code string
// ReturnTypeAttribute if non-empty returns an attribute in the payload
// type that describes the shape of the method payload.
ReturnTypeAttribute string
// ReturnTypeAttributePointer is true if the return type attribute
// generated struct field holds a pointer
ReturnTypeAttributePointer bool
// ReturnIsStruct if true indicates that the method payload is an object.
ReturnIsStruct bool
// ReturnTypeName is the fully-qualified name of the payload.
ReturnTypeName string
// ReturnTypePkg is the package name where the payload is present.
ReturnTypePkg string
// Args is the list of arguments for the constructor.
Args []*codegen.InitArgData
}
PayloadInitData contains the data needed to generate a constructor function that initializes a service method payload type from the command-ling arguments.
type SubcommandData ¶
type SubcommandData struct {
// Name is the sub-command name e.g. "add"
Name string
// FullName is the sub-command full name e.g. "storageAdd"
FullName string
// Description is the help text.
Description string
// MethodVarName is the endpoint method name, e.g. "Add"
MethodVarName string
// BuildFunction contains the data to generate a payload builder function
// if any.
BuildFunction *BuildFunctionData
}
SubcommandData contains the data needed to render a sub-command.
func BuildSubcommandData ¶
func BuildSubcommandData(svcName string, m *service.MethodData, buildFunction *BuildFunctionData) *SubcommandData
BuildSubcommandData builds the data needed by CLI code generators to render the CLI parsing of the service sub-command.