checkpoint: move usage funcs to separate internal package and auto-generate summaries

This commit is contained in:
Dan Anglin 2024-08-12 17:25:08 +01:00
parent bb815b05ce
commit b1f9377788
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
13 changed files with 152 additions and 163 deletions

View file

@ -2,6 +2,7 @@ package main
import ( import (
"embed" "embed"
"errors"
"flag" "flag"
"fmt" "fmt"
"os" "os"
@ -12,9 +13,13 @@ import (
) )
func main() { func main() {
var enbasCLISchemaFilepath string var (
enbasCLISchemaFilepath string
packageName string
)
flag.StringVar(&enbasCLISchemaFilepath, "path-to-enbas-cli-schema", "", "The path to the Enbas CLI schema file") flag.StringVar(&enbasCLISchemaFilepath, "path-to-enbas-cli-schema", "", "The path to the Enbas CLI schema file")
flag.StringVar(&packageName, "package", "", "The name of the internal package")
flag.Parse() flag.Parse()
schema, err := newEnbasCLISchemaFromFile(enbasCLISchemaFilepath) schema, err := newEnbasCLISchemaFromFile(enbasCLISchemaFilepath)
@ -22,16 +27,24 @@ func main() {
fmt.Printf("ERROR: Unable to read the schema file: %v.\n", err) fmt.Printf("ERROR: Unable to read the schema file: %v.\n", err)
} }
if err := generateExecutors(schema); err != nil { if err := generateExecutors(schema, packageName); err != nil {
fmt.Printf("ERROR: Unable to generate the executors: %v.\n", err) fmt.Printf("ERROR: Unable to generate the executors: %v.\n", err)
} }
} }
//go:embed templates/executor/* //go:embed templates/*
var executorTemplates embed.FS var executorTemplates embed.FS
func generateExecutors(schema enbasCLISchema) error { var errNoPackageFlag = errors.New("the --package flag must be used")
fsDir, err := executorTemplates.ReadDir("templates/executor")
func generateExecutors(schema enbasCLISchema, packageName string) error {
if packageName == "" {
return errNoPackageFlag
}
dirName := "templates/" + packageName
fsDir, err := executorTemplates.ReadDir(dirName)
if err != nil { if err != nil {
return fmt.Errorf("unable to read the template directory in the file system (FS): %w", err) return fmt.Errorf("unable to read the template directory in the file system (FS): %w", err)
} }
@ -54,7 +67,7 @@ func generateExecutors(schema enbasCLISchema) error {
if err := func() error { if err := func() error {
tmpl := template.Must(template.New(templateFilename). tmpl := template.Must(template.New(templateFilename).
Funcs(funcMap). Funcs(funcMap).
ParseFS(executorTemplates, "templates/executor/"+templateFilename), ParseFS(executorTemplates, dirName+"/"+templateFilename),
) )
output := strings.TrimSuffix(templateFilename, ".gotmpl") output := strings.TrimSuffix(templateFilename, ".gotmpl")

View file

@ -11,6 +11,7 @@ package executor
{{ print "" }} {{ print "" }}
{{ print "" }} {{ print "" }}
import internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" import internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
import "codeflow.dananglin.me.uk/apollo/enbas/internal/usage"
{{ print "" }} {{ print "" }}
{{ print "" }} {{ print "" }}
type Executor interface { type Executor interface {
@ -83,7 +84,7 @@ func {{ $new_executor_function_name }}(
{{ print "" }} {{ print "" }}
} }
{{ print "" }} {{ print "" }}
exe.Usage = commandUsageFunc({{ printf "%q" $name }}, {{ printf "%q" $command.Summary }}, exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc({{ printf "%q" $name }}, {{ printf "%q" $command.Summary }}, exe.FlagSet)
{{ print "" }} {{ print "" }}
{{- range $flag := $command.Flags -}} {{- range $flag := $command.Flags -}}
{{- $flag_type := getFlagType $flag.Flag -}} {{- $flag_type := getFlagType $flag.Flag -}}

View file

@ -0,0 +1,18 @@
{{- /* 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 usage
{{ print "" }}
var summaries = map[string]string {
{{- range $name, $command := . -}}
{{ print "" }}
{{ printf "%q" $name }}: {{ printf "%q" $command.Summary }},
{{- end -}}
{{ print "" }}
}

View file

@ -6,6 +6,7 @@ import (
"codeflow.dananglin.me.uk/apollo/enbas/internal/executor" "codeflow.dananglin.me.uk/apollo/enbas/internal/executor"
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
"codeflow.dananglin.me.uk/apollo/enbas/internal/usage"
) )
func main() { func main() {
@ -23,7 +24,7 @@ func run() error {
flag.StringVar(&configDir, "config-dir", "", "Specify your config directory") flag.StringVar(&configDir, "config-dir", "", "Specify your config directory")
flag.Var(&noColorFlag, "no-color", "Disable ANSI colour output when displaying text on screen") flag.Var(&noColorFlag, "no-color", "Disable ANSI colour output when displaying text on screen")
flag.Usage = usageFunc(executor.CommandSummaryMap()) flag.Usage = usage.AppUsageFunc()
flag.Parse() flag.Parse()

View file

@ -1,53 +1,2 @@
package main package main
import (
"flag"
"fmt"
"slices"
"strings"
"text/tabwriter"
"codeflow.dananglin.me.uk/apollo/enbas/internal/version"
)
func usageFunc(summaries map[string]string) func() {
cmds := make([]string, len(summaries))
ind := 0
for k := range summaries {
cmds[ind] = k
ind++
}
slices.Sort(cmds)
return func() {
var builder strings.Builder
builder.WriteString("SUMMARY:\n enbas - A GoToSocial client for the terminal.\n\n")
if version.BinaryVersion != "" {
builder.WriteString("VERSION:\n " + version.BinaryVersion + "\n\n")
}
builder.WriteString("USAGE:\n enbas [flags]\n enbas [flags] [command]\n\nCOMMANDS:")
tableWriter := tabwriter.NewWriter(&builder, 0, 8, 0, '\t', 0)
for _, cmd := range cmds {
fmt.Fprintf(tableWriter, "\n %s\t%s", cmd, summaries[cmd])
}
tableWriter.Flush()
builder.WriteString("\n\nFLAGS:\n --help\n print the help message")
flag.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(&builder, "\n --%s\n %s", f.Name, f.Usage)
})
builder.WriteString("\n\nUse \"enbas [command] --help\" for more information about a command.\n")
w := flag.CommandLine.Output()
fmt.Fprint(w, builder.String())
}
}

View file

@ -1,3 +1,3 @@
package executor package executor
//go:generate go run ../../cmd/enbas-codegen --path-to-enbas-cli-schema ../../schema/enbas_cli_schema.json //go:generate go run ../../cmd/enbas-codegen --package executor --path-to-enbas-cli-schema ../../schema/enbas_cli_schema.json

View file

@ -1,78 +0,0 @@
package executor
const (
commandAccept string = "accept"
commandAdd string = "add"
commandBlock string = "block"
commandCreate string = "create"
commandDelete string = "delete"
commandEdit string = "edit"
commandFollow string = "follow"
commandInit string = "init"
commandLogin string = "login"
commandMute string = "mute"
commandReject string = "reject"
commandRemove string = "remove"
commandShow string = "show"
commandSwitch string = "switch"
commandUnblock string = "unblock"
commandUnfollow string = "unfollow"
commandUnmute string = "unmute"
commandVersion string = "version"
commandWhoami string = "whoami"
commandAcceptSummary string = "Accept a request (e.g. a follow request)"
commandAddSummary string = "Add a resource to another resource"
commandBlockSummary string = "Block a resource (e.g. an account)"
commandCreateSummary string = "Create a specific resource"
commandDeleteSummary string = "Delete a specific resource"
commandEditSummary string = "Edit a specific resource"
commandFollowSummary string = "Follow a resource (e.g. an account)"
commandInitSummary string = "Create a new configuration file in the specified configuration directory"
commandLoginSummary string = "Login to an account on GoToSocial"
commandMuteSummary string = "Mute a resource (e.g. an account)"
commandRejectSummary string = "Reject a request (e.g. a follow request)"
commandRemoveSummary string = "Remove a resource from another resource"
commandShowSummary string = "Print details about a specified resource"
commandSwitchSummary string = "Perform a switch operation (e.g. switch logged in accounts)"
commandUnblockSummary string = "Unblock a resource (e.g. an account)"
commandUnfollowSummary string = "Unfollow a resource (e.g. an account)"
commandUnmuteSummary string = "Unmute a resource (e.g. an account)"
commandVersionSummary string = "Print the application's version and build information"
commandWhoamiSummary string = "Print the account that you are currently logged in to"
)
func CommandSummaryMap() map[string]string {
return map[string]string{
commandAccept: commandAcceptSummary,
commandAdd: commandAddSummary,
commandBlock: commandBlockSummary,
commandCreate: commandCreateSummary,
commandDelete: commandDeleteSummary,
commandEdit: commandEditSummary,
commandFollow: commandFollowSummary,
commandInit: commandInitSummary,
commandLogin: commandLoginSummary,
commandMute: commandMuteSummary,
commandReject: commandRejectSummary,
commandRemove: commandRemoveSummary,
commandShow: commandShowSummary,
commandSwitch: commandSwitchSummary,
commandUnblock: commandUnblockSummary,
commandUnfollow: commandUnfollowSummary,
commandUnmute: commandUnmuteSummary,
commandVersion: commandVersionSummary,
commandWhoami: commandWhoamiSummary,
}
}
func CommandSummaryLookup(command string) string {
commandMap := CommandSummaryMap()
summary, ok := commandMap[command]
if !ok {
return "This command does not have a summary"
}
return summary
}

View file

@ -11,6 +11,7 @@ import (
"codeflow.dananglin.me.uk/apollo/enbas/internal/config" "codeflow.dananglin.me.uk/apollo/enbas/internal/config"
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer" "codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
"codeflow.dananglin.me.uk/apollo/enbas/internal/usage"
) )
type Executor interface { type Executor interface {
@ -39,7 +40,7 @@ func NewAcceptExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("accept", "Accepts a request (e.g. a follow request)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("accept", "Accepts a request (e.g. a follow request)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -74,7 +75,7 @@ func NewAddExecutor(
votes: internalFlag.NewIntSliceValue(), votes: internalFlag.NewIntSliceValue(),
} }
exe.Usage = commandUsageFunc("add", "Add a resource to another resource", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("add", "Adds a resource to another resource", exe.FlagSet)
exe.Var(&exe.accountNames, "account-name", "The name of the account") exe.Var(&exe.accountNames, "account-name", "The name of the account")
exe.StringVar(&exe.content, "content", "", "The content of the created resource") exe.StringVar(&exe.content, "content", "", "The content of the created resource")
@ -108,7 +109,7 @@ func NewBlockExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("block", "Blocks a resource (e.g. an account)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("block", "Blocks a resource (e.g. an account)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -156,7 +157,7 @@ func NewCreateExecutor(
sensitive: internalFlag.NewBoolPtrValue(), sensitive: internalFlag.NewBoolPtrValue(),
} }
exe.Usage = commandUsageFunc("create", "Creates a specific resource", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("create", "Creates a specific resource", exe.FlagSet)
exe.BoolVar(&exe.addPoll, "add-poll", false, "Set to true to add a poll when creating a status") exe.BoolVar(&exe.addPoll, "add-poll", false, "Set to true to add a poll when creating a status")
exe.StringVar(&exe.content, "content", "", "The content of the created resource") exe.StringVar(&exe.content, "content", "", "The content of the created resource")
@ -201,7 +202,7 @@ func NewDeleteExecutor(
config: config, config: config,
} }
exe.Usage = commandUsageFunc("delete", "Deletes a specific resource", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("delete", "Deletes a specific resource", exe.FlagSet)
exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -230,7 +231,7 @@ func NewEditExecutor(
config: config, config: config,
} }
exe.Usage = commandUsageFunc("edit", "Edit a specific resource", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("edit", "Edit a specific resource", exe.FlagSet)
exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question")
exe.StringVar(&exe.listTitle, "list-title", "", "The title of the list") exe.StringVar(&exe.listTitle, "list-title", "", "The title of the list")
@ -262,7 +263,7 @@ func NewFollowExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("follow", "Follow a resource (e.g. an account)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("follow", "Follow a resource (e.g. an account)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.BoolVar(&exe.notify, "notify", false, "Get notifications from statuses from the account you want to follow") exe.BoolVar(&exe.notify, "notify", false, "Get notifications from statuses from the account you want to follow")
@ -289,7 +290,7 @@ func NewInitExecutor(
configDir: configDir, configDir: configDir,
} }
exe.Usage = commandUsageFunc("init", "Creates a new configuration file in the specified configuration directory", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("init", "Creates a new configuration file in the specified configuration directory", exe.FlagSet)
return &exe return &exe
} }
@ -312,7 +313,7 @@ func NewLoginExecutor(
config: config, config: config,
} }
exe.Usage = commandUsageFunc("login", "Logs into an account on GoToSocial", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("login", "Logs into an account on GoToSocial", exe.FlagSet)
exe.StringVar(&exe.instance, "instance", "", "The instance that you want to log into") exe.StringVar(&exe.instance, "instance", "", "The instance that you want to log into")
@ -342,7 +343,7 @@ func NewMuteExecutor(
muteDuration: internalFlag.NewTimeDurationValue(), muteDuration: internalFlag.NewTimeDurationValue(),
} }
exe.Usage = commandUsageFunc("mute", "Mutes a specific resource (e.g. an account)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("mute", "Mutes a specific resource (e.g. an account)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.Var(&exe.muteDuration, "mute-duration", "Specify how long the mute should last for. To mute indefinitely, set this to 0s") exe.Var(&exe.muteDuration, "mute-duration", "Specify how long the mute should last for. To mute indefinitely, set this to 0s")
@ -372,7 +373,7 @@ func NewRejectExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("reject", "Rejects a request (e.g. a follow request)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("reject", "Rejects a request (e.g. a follow request)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -403,7 +404,7 @@ func NewRemoveExecutor(
accountNames: internalFlag.NewStringSliceValue(), accountNames: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("remove", "", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("remove", "Removes a resource from another resource", exe.FlagSet)
exe.Var(&exe.accountNames, "account-name", "The name of the account") exe.Var(&exe.accountNames, "account-name", "The name of the account")
exe.StringVar(&exe.fromResourceType, "from", "", "Specify the resource type to action the target resource from") exe.StringVar(&exe.fromResourceType, "from", "", "Specify the resource type to action the target resource from")
@ -455,7 +456,7 @@ func NewShowExecutor(
attachmentIDs: internalFlag.NewStringSliceValue(), attachmentIDs: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("show", "Shows details about a specified resource", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("show", "Shows details about a specified resource", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.BoolVar(&exe.getAllImages, "all-images", false, "Set to true to show all images from a status") exe.BoolVar(&exe.getAllImages, "all-images", false, "Set to true to show all images from a status")
@ -503,7 +504,7 @@ func NewSwitchExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("switch", "Performs a switch operation (e.g. switching between logged in accounts)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("switch", "Performs a switch operation (e.g. switching between logged in accounts)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.to, "to", "", "TBC") exe.StringVar(&exe.to, "to", "", "TBC")
@ -531,7 +532,7 @@ func NewUnblockExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("unblock", "Unblocks a resource (e.g. an account)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("unblock", "Unblocks a resource (e.g. an account)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -559,7 +560,7 @@ func NewUnfollowExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("unfollow", "Unfollow a resource (e.g. an account)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("unfollow", "Unfollows a resource (e.g. an account)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -587,7 +588,7 @@ func NewUnmuteExecutor(
accountName: internalFlag.NewStringSliceValue(), accountName: internalFlag.NewStringSliceValue(),
} }
exe.Usage = commandUsageFunc("unmute", "Umutes a specific resource (e.g. an account)", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("unmute", "Umutes a specific resource (e.g. an account)", exe.FlagSet)
exe.Var(&exe.accountName, "account-name", "The name of the account") exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -610,7 +611,7 @@ func NewVersionExecutor(
printer: printer, printer: printer,
} }
exe.Usage = commandUsageFunc("version", "Prints the application's version and build information", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("version", "Prints the application's version and build information", exe.FlagSet)
exe.BoolVar(&exe.full, "full", false, "Set to true to print the build information in full") exe.BoolVar(&exe.full, "full", false, "Set to true to print the build information in full")
@ -634,7 +635,7 @@ func NewWhoamiExecutor(
config: config, config: config,
} }
exe.Usage = commandUsageFunc("whoami", "Prints the account that you are currently logged into", exe.FlagSet) exe.Usage = usage.ExecutorUsageFunc("whoami", "Prints the account that you are currently logged into", exe.FlagSet)
return &exe return &exe
} }

53
internal/usage/app.go Normal file
View file

@ -0,0 +1,53 @@
package usage
import (
"flag"
"fmt"
"slices"
"strings"
"text/tabwriter"
"codeflow.dananglin.me.uk/apollo/enbas/internal/version"
)
func AppUsageFunc() func() {
cmds := make([]string, len(summaries))
ind := 0
for k := range summaries {
cmds[ind] = k
ind++
}
slices.Sort(cmds)
return func() {
var builder strings.Builder
builder.WriteString("SUMMARY:\n enbas - A GoToSocial client for the terminal.\n\n")
if version.BinaryVersion != "" {
builder.WriteString("VERSION:\n " + version.BinaryVersion + "\n\n")
}
builder.WriteString("USAGE:\n enbas [flags]\n enbas [flags] [command]\n\nCOMMANDS:")
tableWriter := tabwriter.NewWriter(&builder, 0, 8, 0, '\t', 0)
for _, cmd := range cmds {
fmt.Fprintf(tableWriter, "\n %s\t%s", cmd, summaries[cmd])
}
tableWriter.Flush()
builder.WriteString("\n\nFLAGS:\n --help\n print the help message")
flag.VisitAll(func(f *flag.Flag) {
fmt.Fprintf(&builder, "\n --%s\n %s", f.Name, f.Usage)
})
builder.WriteString("\n\nUse \"enbas [command] --help\" for more information about a command.\n")
w := flag.CommandLine.Output()
fmt.Fprint(w, builder.String())
}
}

View file

@ -0,0 +1,3 @@
package usage
//go:generate go run ../../cmd/enbas-codegen --package usage --path-to-enbas-cli-schema ../../schema/enbas_cli_schema.json

View file

@ -1,4 +1,4 @@
package executor package usage
import ( import (
"flag" "flag"
@ -6,8 +6,8 @@ import (
"strings" "strings"
) )
// commandUsageFunc returns the function used to print a command's help page. // ExecutorUsageFunc returns the function used to print a command's help page.
func commandUsageFunc(name, summary string, flagset *flag.FlagSet) func() { func ExecutorUsageFunc(name, summary string, flagset *flag.FlagSet) func() {
return func() { return func() {
var builder strings.Builder var builder strings.Builder

View file

@ -0,0 +1,28 @@
/*
This file is generated by the enbas-codegen
DO NOT EDIT.
*/
package usage
var summaries = map[string]string{
"accept": "Accepts a request (e.g. a follow request)",
"add": "Adds a resource to another resource",
"block": "Blocks a resource (e.g. an account)",
"create": "Creates a specific resource",
"delete": "Deletes a specific resource",
"edit": "Edit a specific resource",
"follow": "Follow a resource (e.g. an account)",
"init": "Creates a new configuration file in the specified configuration directory",
"login": "Logs into an account on GoToSocial",
"mute": "Mutes a specific resource (e.g. an account)",
"reject": "Rejects a request (e.g. a follow request)",
"remove": "Removes a resource from another resource",
"show": "Shows details about a specified resource",
"switch": "Performs a switch operation (e.g. switching between logged in accounts)",
"unblock": "Unblocks a resource (e.g. an account)",
"unfollow": "Unfollows a resource (e.g. an account)",
"unmute": "Umutes a specific resource (e.g. an account)",
"version": "Prints the application's version and build information",
"whoami": "Prints the account that you are currently logged into",
}

View file

@ -221,7 +221,7 @@
{ "flag": "type", "fieldName": "resourceType", "default": "" }, { "flag": "type", "fieldName": "resourceType", "default": "" },
{ "flag": "vote", "fieldName": "votes" } { "flag": "vote", "fieldName": "votes" }
], ],
"summary": "Add a resource to another resource", "summary": "Adds a resource to another resource",
"useConfig": true, "useConfig": true,
"usePrinter": true "usePrinter": true
}, },
@ -346,7 +346,7 @@
{ "flag": "status-id", "fieldName": "statusID", "default": "" }, { "flag": "status-id", "fieldName": "statusID", "default": "" },
{ "flag": "type", "fieldName": "resourceType", "default": "" } { "flag": "type", "fieldName": "resourceType", "default": "" }
], ],
"summary": "", "summary": "Removes a resource from another resource",
"useConfig": true, "useConfig": true,
"usePrinter": true "usePrinter": true
}, },
@ -406,7 +406,7 @@
{ "flag": "account-name" }, { "flag": "account-name" },
{ "flag": "type", "fieldName": "resourceType", "default": "" } { "flag": "type", "fieldName": "resourceType", "default": "" }
], ],
"summary": "Unfollow a resource (e.g. an account)", "summary": "Unfollows a resource (e.g. an account)",
"useConfig": true, "useConfig": true,
"usePrinter": true "usePrinter": true
}, },