checkpoint: removed interface, update template, hit a blocker

This commit is contained in:
Dan Anglin 2024-08-21 08:28:55 +01:00
parent 74f32aab53
commit 60079f9bf1
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
2 changed files with 17 additions and 28 deletions

View file

@ -13,15 +13,9 @@ package executor
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" -}}
{{- $execute_command_function_name := capitalise $name | printf "Execute%sCommand" -}}
{{ print "" }}
// {{ $struct_name }} is the executor for the {{ $name }} command.
type {{ $struct_name }} struct {
@ -49,27 +43,16 @@ type {{ $struct_name }} struct {
{{ print "" }}
}
func {{ $new_executor_function_name }}(
{{- if $command.UsePrinter }}
// {{ $execute_command_function_name }} initialises and runs the executor for the {{ $name }} command.
func {{ $execute_command_function_name }}(
printer *printer.Printer,
{{- end }}
{{- if $command.UseConfig }}
config *config.Config,
{{- end }}
{{- range $field := $command.AdditionalFields -}}
{{ print "" }}
{{ $field.Name }} {{ $field.Type }},
{{- end -}}
{{ print "" }}
) *{{ $struct_name }} {
args []string,
) error {
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 -}}
@ -77,10 +60,6 @@ func {{ $new_executor_function_name }}(
{{ flagFieldName $flag }}: internalFlag.New{{ $flag_type }}(),
{{- end -}}
{{- end -}}
{{- range $field := $command.AdditionalFields -}}
{{ print "" }}
{{ $field.Name }}: {{ $field.Name }},
{{- end -}}
{{ print "" }}
}
{{ print "" }}
@ -104,6 +83,16 @@ func {{ $new_executor_function_name }}(
{{- end -}}
{{ print "" }}
{{ print "" }}
return &exe
if err := exe.Parse(args); err != nil {
return fmt.Errorf("flag parsing error: %w", err)
}
{{ print "" }}
{{ print "" }}
if err := exe.Execute(); err != nil {
return fmt.Errorf("execution error: %w", err)
}
{{ print "" }}
{{ print "" }}
return nil
}
{{ end }}

View file

@ -318,7 +318,7 @@
],
"flags": [],
"summary": "Creates a new configuration file in the specified configuration directory",
"useConfig": false,
"useConfig": true,
"usePrinter": true
},
"login": {