checkpoint: additional fields

This commit is contained in:
Dan Anglin 2024-08-09 19:28:03 +01:00
parent e16852da97
commit d1f5e57703
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
3 changed files with 40 additions and 14 deletions

View file

@ -53,13 +53,19 @@ func (e enbasCLISchemaFlagMap) getDescription(name string) string {
}
type enbasCLISchemaCommand struct {
UsePrinter bool `json:"usePrinter"`
UseConfig bool `json:"useConfig"`
Flags []enbasCLISchemaFlagReference `json:"flags"`
Summary string `json:"summary"`
AdditionalFields []enbasCLISchemaAdditionalFields `json:"additionalFields"`
Flags []enbasCLISchemaFlagReference `json:"flags"`
Summary string `json:"summary"`
UseConfig bool `json:"useConfig"`
UsePrinter bool `json:"usePrinter"`
}
type enbasCLISchemaFlagReference struct {
Flag string `json:"flag"`
Default string `json:"default"`
}
type enbasCLISchemaAdditionalFields struct {
Name string `json:"name"`
Type string `json:"type"`
}

View file

@ -18,6 +18,10 @@ type {{ $struct_name }} struct {
{{ print "" }}
{{ $flag.Flag }} {{ getFlagType $flag.Flag }}
{{- end -}}
{{- range $field := $command.AdditionalFields -}}
{{ print "" }}
{{ $field.Name }} {{ $field.Type }}
{{- end -}}
{{ print "" }}
}
@ -28,6 +32,11 @@ func {{ $new_executor_function_name }}(
{{- 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),
@ -37,6 +46,11 @@ func {{ $new_executor_function_name }}(
{{- if $command.UseConfig }}
config: config,
{{- end }}
{{- range $field := $command.AdditionalFields -}}
{{ print "" }}
{{ $field.Name }}: {{ $field.Name }},
{{- end -}}
{{ print "" }}
}
{{ print "" }}
exe.Usage = commandUsageFunc({{ printf "%q" $name }}, {{ printf "%q" $command.Summary }}, exe.FlagSet)

View file

@ -12,26 +12,32 @@
"commands": {
"login": {
"usePrinter": true,
"useConfig": true,
"flags": [
{ "flag": "instance", "default": "" }
],
"summary": "Login to an account on GoToSocial"
"summary": "Log into an account on GoToSocial",
"useConfig": true,
"usePrinter": true
},
"version": {
"usePrinter": true,
"useConfig": false,
"summary": "Prints the application's version and build information",
"additionalFields": [
{ "name": "binaryVersion", "type": "string"},
{ "name": "buildTime", "type": "string"},
{ "name": "goVersion", "type": "string"},
{ "name": "gitCommit", "type": "string"}
],
"flags": [
{ "flag": "full", "default": "false" }
]
],
"summary": "Prints the application's version and build information",
"useConfig": false,
"usePrinter": true
},
"whoami": {
"usePrinter": true,
"useConfig": true,
"flags": [],
"summary": "Prints the account that you are currently logged into",
"flags": []
"useConfig": true,
"usePrinter": true
}
}
}