Dan Anglin
84091f398d
Summary: - Created a custom CLI schema for Enbas which will act as the Source of Truth for code and document generation. - Created a code generator which uses the schema to generate the executor definitions and code in the internal usage package. Changes: - Created the Enbas CLI schema as the Source of Truth for Enbas. - Created the code generator that generates the executor definitions and code in the usage package. - Regenerated the executor definitions using the code generator. - Moved the custom flag value types to the new internal flag package. - Created a new flag value type for the bool pointer to replace the flag.BoolFunc() used for the sensitive and no-color flags. - Moved the version and build variables to the new internal version package to simplify the version executor. - Created a new usage package and moved the usage functions there. - Changed the type of the account-name flag from string to the internal StringSliceValue type.
109 lines
3.4 KiB
Go Template
109 lines
3.4 KiB
Go Template
{{- /* vim: set noexpandtab : */ -}}
|
|
{{- /* vim: set tabstop=8 : */ -}}
|
|
{{- /* vim: set shiftwidth=8 : */ -}}
|
|
{{- /* vim: set softtabstop=8 : */ -}}
|
|
/*
|
|
This file is generated by the enbas-codegen
|
|
DO NOT EDIT.
|
|
*/
|
|
{{ print "" }}
|
|
package executor
|
|
{{ print "" }}
|
|
{{ print "" }}
|
|
import internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
|
import "codeflow.dananglin.me.uk/apollo/enbas/internal/usage"
|
|
{{ print "" }}
|
|
{{ print "" }}
|
|
type Executor interface {
|
|
Name() string
|
|
Parse(args []string) error
|
|
Execute() error
|
|
}
|
|
{{ range $name, $command := . }}
|
|
{{- $struct_name := capitalise $name | printf "%sExecutor" -}}
|
|
{{- $new_executor_function_name := capitalise $name | printf "New%sExecutor" -}}
|
|
{{ print "" }}
|
|
// {{ $struct_name }} is the executor for the {{ $name }} command.
|
|
type {{ $struct_name }} struct {
|
|
*flag.FlagSet
|
|
{{- if $command.UsePrinter }}
|
|
printer *printer.Printer
|
|
{{- end }}
|
|
{{- if $command.UseConfig }}
|
|
config *config.Config
|
|
{{- end }}
|
|
{{- range $flag := $command.Flags -}}
|
|
{{- $flag_type := getFlagType $flag.Flag -}}
|
|
{{- if internalFlagValue $flag_type -}}
|
|
{{ print "" }}
|
|
{{ flagFieldName $flag }} internalFlag.{{ $flag_type }}
|
|
{{- else -}}
|
|
{{ print "" }}
|
|
{{ flagFieldName $flag }} {{ $flag_type }}
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- range $field := $command.AdditionalFields -}}
|
|
{{ print "" }}
|
|
{{ $field.Name }} {{ $field.Type }}
|
|
{{- end -}}
|
|
{{ print "" }}
|
|
}
|
|
|
|
func {{ $new_executor_function_name }}(
|
|
{{- if $command.UsePrinter }}
|
|
printer *printer.Printer,
|
|
{{- end }}
|
|
{{- if $command.UseConfig }}
|
|
config *config.Config,
|
|
{{- end }}
|
|
{{- range $field := $command.AdditionalFields -}}
|
|
{{ print "" }}
|
|
{{ $field.Name }} {{ $field.Type }},
|
|
{{- end -}}
|
|
{{ print "" }}
|
|
) *{{ $struct_name }} {
|
|
exe := {{ $struct_name }}{
|
|
FlagSet: flag.NewFlagSet({{ printf "%q" $name }}, flag.ExitOnError),
|
|
{{- if $command.UsePrinter }}
|
|
printer: printer,
|
|
{{- end }}
|
|
{{- if $command.UseConfig }}
|
|
config: config,
|
|
{{- end }}
|
|
{{- range $flag := $command.Flags -}}
|
|
{{- $flag_type := getFlagType $flag.Flag -}}
|
|
{{- if internalFlagValue $flag_type -}}
|
|
{{ print "" }}
|
|
{{ flagFieldName $flag }}: internalFlag.New{{ $flag_type }}(),
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{- range $field := $command.AdditionalFields -}}
|
|
{{ print "" }}
|
|
{{ $field.Name }}: {{ $field.Name }},
|
|
{{- end -}}
|
|
{{ print "" }}
|
|
}
|
|
{{ print "" }}
|
|
exe.Usage = usage.ExecutorUsageFunc({{ printf "%q" $name }}, {{ printf "%q" $command.Summary }}, exe.FlagSet)
|
|
{{ print "" }}
|
|
{{- range $flag := $command.Flags -}}
|
|
{{- $flag_type := getFlagType $flag.Flag -}}
|
|
{{- if eq $flag_type "string" -}}
|
|
{{ print "" }}
|
|
exe.StringVar(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ printf "%q" $flag.Default }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
|
{{- else if eq $flag_type "bool" -}}
|
|
{{ print "" }}
|
|
exe.BoolVar(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ $flag.Default }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
|
{{- else if eq $flag_type "int" -}}
|
|
{{ print "" }}
|
|
exe.IntVar(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ $flag.Default }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
|
{{- else if internalFlagValue $flag_type -}}
|
|
{{ print "" }}
|
|
exe.Var(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ getFlagDescription $flag.Flag | printf "%q" }})
|
|
{{- end -}}
|
|
{{- end -}}
|
|
{{ print "" }}
|
|
{{ print "" }}
|
|
return &exe
|
|
}
|
|
{{ end }}
|