From 5576a8c98630614e1310bc7814236ec0bc8c5965 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 21 Aug 2024 12:01:41 +0100 Subject: [PATCH] Done: I'm so happy --- .../templates/executor/execute.go.gotmpl | 133 -- ...executors.go.gotmpl => executor.go.gotmpl} | 109 +- internal/executor/execute.go | 184 --- internal/executor/executor.go | 1361 +++++++++++++++++ internal/executor/executors.go | 664 -------- schema/enbas_cli_schema.json | 74 +- 6 files changed, 1511 insertions(+), 1014 deletions(-) delete mode 100644 cmd/enbas-codegen/templates/executor/execute.go.gotmpl rename cmd/enbas-codegen/templates/executor/{executors.go.gotmpl => executor.go.gotmpl} (56%) delete mode 100644 internal/executor/execute.go create mode 100644 internal/executor/executor.go delete mode 100644 internal/executor/executors.go diff --git a/cmd/enbas-codegen/templates/executor/execute.go.gotmpl b/cmd/enbas-codegen/templates/executor/execute.go.gotmpl deleted file mode 100644 index 16a75d6..0000000 --- a/cmd/enbas-codegen/templates/executor/execute.go.gotmpl +++ /dev/null @@ -1,133 +0,0 @@ -{{- /* 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 "fmt" -import "flag" -import "os" -import "codeflow.dananglin.me.uk/apollo/enbas/internal/config" -import internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" -import "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" -import "codeflow.dananglin.me.uk/apollo/enbas/internal/usage" -{{ print "" }} -{{ print "" }} -func Execute() error { - var ( - configDir string - noColorFlag internalFlag.BoolPtrValue - noColor bool - enbasConfig *config.Config - enbasPrinter *printer.Printer - err error - ) - - flag.StringVar(&configDir, "config-dir", "", "The path to your configuration directory") - flag.Var(&noColorFlag, "no-color", "Set to true to disable ANSI colour output when displaying text on screen") - - flag.Usage = usage.AppUsageFunc() - - flag.Parse() - - if flag.NArg() < 1 { - flag.Usage() - - return nil - } - - if noColorFlag.Value != nil { - noColor = *noColorFlag.Value - } else if os.Getenv("NO_COLOR") != "" { - noColor = true - } - - command := flag.Arg(0) - args := flag.Args()[1:] - - switch command { - case "init", "version": - enbasPrinter = printer.NewPrinter(noColor, "", 0) - default: - enbasConfig, err = config.NewConfigFromFile(configDir) - if err != nil { - enbasPrinter = printer.NewPrinter(noColor, "", 0) - enbasPrinter.PrintFailure("unable to load the configuration: " + err.Error() + ".") - - return err - } - - enbasPrinter = printer.NewPrinter( - noColor, - enbasConfig.Integrations.Pager, - enbasConfig.LineWrapMaxWidth, - ) - } - - if err = execute( - command, - args, - enbasPrinter, - enbasConfig, - configDir, - ); err != nil { - enbasPrinter.PrintFailure("(" + command + ") " + err.Error() + ".") - - return err - } - - return nil -} -{{ print "" }} -{{ print "" }} -func execute( - command string, - args []string, - enbasPrinter *printer.Printer, - enbasConfig *config.Config, - configDir string, -) error { - executorMap := map[string]Executor{ - {{- range $name, $command := . -}} - {{- $new_executor_function_name := capitalise $name | printf "New%sExecutor" -}} - {{ print "" }} - {{ printf "%q" $name }}: {{ $new_executor_function_name }}( - {{- if $command.UsePrinter -}} - {{ print "" }} - enbasPrinter, - {{- end -}} - {{- if $command.UseConfig -}} - {{ print "" }} - enbasConfig, - {{- end -}} - {{- range $field := $command.AdditionalFields -}} - {{ print "" }} - {{ $field.Name }}, - {{- end -}} - {{ print "" }} - ), - {{- end -}} - {{ print "" }} - } - - exe, ok := executorMap[command] - if !ok { - return UnknownCommandError{command: command} - } - - if err := exe.Parse(args); err != nil { - return fmt.Errorf("flag parsing error: %w", err) - } - - if err := exe.Execute(); err != nil { - return fmt.Errorf("execution error: %w", err) - } - - return nil -} diff --git a/cmd/enbas-codegen/templates/executor/executors.go.gotmpl b/cmd/enbas-codegen/templates/executor/executor.go.gotmpl similarity index 56% rename from cmd/enbas-codegen/templates/executor/executors.go.gotmpl rename to cmd/enbas-codegen/templates/executor/executor.go.gotmpl index e4beb74..e57007b 100644 --- a/cmd/enbas-codegen/templates/executor/executors.go.gotmpl +++ b/cmd/enbas-codegen/templates/executor/executor.go.gotmpl @@ -10,9 +10,64 @@ package executor {{ print "" }} {{ print "" }} +import "fmt" +import "flag" +import "os" +import "codeflow.dananglin.me.uk/apollo/enbas/internal/config" import internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" +import "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" import "codeflow.dananglin.me.uk/apollo/enbas/internal/usage" {{ print "" }} +{{ print "" }} +func Execute() error { + var ( + configDir string + noColorFlag internalFlag.BoolPtrValue + noColor bool + ) + + flag.StringVar(&configDir, "config-dir", "", "The path to your configuration directory") + flag.Var(&noColorFlag, "no-color", "Set to true to disable ANSI colour output when displaying text on screen") + + flag.Usage = usage.AppUsageFunc() + + flag.Parse() + + if flag.NArg() < 1 { + flag.Usage() + + return nil + } + + if noColorFlag.Value != nil { + noColor = *noColorFlag.Value + } else if os.Getenv("NO_COLOR") != "" { + noColor = true + } + + command := flag.Arg(0) + args := flag.Args()[1:] + + executorMap := map[string]func(string, bool, []string) error { + {{- range $name, $command := . -}} + {{- $execute_command_function_name := capitalise $name | printf "Execute%sCommand" -}} + {{ print "" }} + {{ printf "%q" $name }}: {{ $execute_command_function_name }}, + {{- end -}} + {{ print "" }} + } + + executorFunc, ok := executorMap[command] + if !ok { + err := UnknownCommandError{command: command} + printer.NewPrinter(noColor, "", 0).PrintFailure("Error: "+err.Error()) + + return err + } + + return executorFunc(configDir, noColor, args) +} +{{ print "" }} {{ range $name, $command := . }} {{- $struct_name := capitalise $name | printf "%sExecutor" -}} {{- $execute_command_function_name := capitalise $name | printf "Execute%sCommand" -}} @@ -20,12 +75,8 @@ import "codeflow.dananglin.me.uk/apollo/enbas/internal/usage" // {{ $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 -}} @@ -45,14 +96,15 @@ type {{ $struct_name }} struct { // {{ $execute_command_function_name }} initialises and runs the executor for the {{ $name }} command. func {{ $execute_command_function_name }}( - printer *printer.Printer, - config *config.Config, + configDir string, + noColor bool, args []string, ) error { exe := {{ $struct_name }}{ FlagSet: flag.NewFlagSet({{ printf "%q" $name }}, flag.ExitOnError), - printer: printer, - config: config, + printer: nil, + config: nil, + configDir: configDir, {{- range $flag := $command.Flags -}} {{- $flag_type := getFlagType $flag.Flag -}} {{- if internalFlagValue $flag_type -}} @@ -81,18 +133,47 @@ func {{ $execute_command_function_name }}( exe.Var(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ getFlagDescription $flag.Flag | printf "%q" }}) {{- end -}} {{- end -}} + {{- if $command.UseConfig -}} {{ print "" }} {{ print "" }} + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("({{ $name }}) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + {{- else -}} + {{ print "" }} + {{ print "" }} + // Create the printer for the executor. + exe.printer = printer.NewPrinter(noColor, "", 0) + {{- end -}} + {{ print "" }} + {{ print "" }} + // Parse the remaining arguments. if err := exe.Parse(args); err != nil { - return fmt.Errorf("flag parsing error: %w", err) + exe.printer.PrintFailure("({{ $name }}) flag parsing error: " + err.Error() + ".") + + return err } - {{ print "" }} - {{ print "" }} + + // Run the executor. if err := exe.Execute(); err != nil { - return fmt.Errorf("execution error: %w", err) + exe.printer.PrintFailure("({{ $name }}) execution error: " + err.Error() + ".") + + return err } - {{ print "" }} - {{ print "" }} + return nil } {{ end }} diff --git a/internal/executor/execute.go b/internal/executor/execute.go deleted file mode 100644 index 44b0616..0000000 --- a/internal/executor/execute.go +++ /dev/null @@ -1,184 +0,0 @@ -/* - This file is generated by the enbas-codegen - DO NOT EDIT. -*/ - -package executor - -import ( - "flag" - "fmt" - "os" - - "codeflow.dananglin.me.uk/apollo/enbas/internal/config" - internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" - "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" - "codeflow.dananglin.me.uk/apollo/enbas/internal/usage" -) - -func Execute() error { - var ( - configDir string - noColorFlag internalFlag.BoolPtrValue - noColor bool - enbasConfig *config.Config - enbasPrinter *printer.Printer - err error - ) - - flag.StringVar(&configDir, "config-dir", "", "The path to your configuration directory") - flag.Var(&noColorFlag, "no-color", "Set to true to disable ANSI colour output when displaying text on screen") - - flag.Usage = usage.AppUsageFunc() - - flag.Parse() - - if flag.NArg() < 1 { - flag.Usage() - - return nil - } - - if noColorFlag.Value != nil { - noColor = *noColorFlag.Value - } else if os.Getenv("NO_COLOR") != "" { - noColor = true - } - - command := flag.Arg(0) - args := flag.Args()[1:] - - switch command { - case "init", "version": - enbasPrinter = printer.NewPrinter(noColor, "", 0) - default: - enbasConfig, err = config.NewConfigFromFile(configDir) - if err != nil { - enbasPrinter = printer.NewPrinter(noColor, "", 0) - enbasPrinter.PrintFailure("unable to load the configuration: " + err.Error() + ".") - - return err - } - - enbasPrinter = printer.NewPrinter( - noColor, - enbasConfig.Integrations.Pager, - enbasConfig.LineWrapMaxWidth, - ) - } - - if err = execute( - command, - args, - enbasPrinter, - enbasConfig, - configDir, - ); err != nil { - enbasPrinter.PrintFailure("(" + command + ") " + err.Error() + ".") - - return err - } - - return nil -} - -func execute( - command string, - args []string, - enbasPrinter *printer.Printer, - enbasConfig *config.Config, - configDir string, -) error { - executorMap := map[string]Executor{ - "accept": NewAcceptExecutor( - enbasPrinter, - enbasConfig, - ), - "add": NewAddExecutor( - enbasPrinter, - enbasConfig, - ), - "block": NewBlockExecutor( - enbasPrinter, - enbasConfig, - ), - "create": NewCreateExecutor( - enbasPrinter, - enbasConfig, - ), - "delete": NewDeleteExecutor( - enbasPrinter, - enbasConfig, - ), - "edit": NewEditExecutor( - enbasPrinter, - enbasConfig, - ), - "follow": NewFollowExecutor( - enbasPrinter, - enbasConfig, - ), - "init": NewInitExecutor( - enbasPrinter, - configDir, - ), - "login": NewLoginExecutor( - enbasPrinter, - enbasConfig, - ), - "mute": NewMuteExecutor( - enbasPrinter, - enbasConfig, - ), - "reject": NewRejectExecutor( - enbasPrinter, - enbasConfig, - ), - "remove": NewRemoveExecutor( - enbasPrinter, - enbasConfig, - ), - "show": NewShowExecutor( - enbasPrinter, - enbasConfig, - ), - "switch": NewSwitchExecutor( - enbasPrinter, - enbasConfig, - ), - "unblock": NewUnblockExecutor( - enbasPrinter, - enbasConfig, - ), - "unfollow": NewUnfollowExecutor( - enbasPrinter, - enbasConfig, - ), - "unmute": NewUnmuteExecutor( - enbasPrinter, - enbasConfig, - ), - "version": NewVersionExecutor( - enbasPrinter, - ), - "whoami": NewWhoamiExecutor( - enbasPrinter, - enbasConfig, - ), - } - - exe, ok := executorMap[command] - if !ok { - return UnknownCommandError{command: command} - } - - if err := exe.Parse(args); err != nil { - return fmt.Errorf("flag parsing error: %w", err) - } - - if err := exe.Execute(); err != nil { - return fmt.Errorf("execution error: %w", err) - } - - return nil -} diff --git a/internal/executor/executor.go b/internal/executor/executor.go new file mode 100644 index 0000000..3e7f86f --- /dev/null +++ b/internal/executor/executor.go @@ -0,0 +1,1361 @@ +/* + This file is generated by the enbas-codegen + DO NOT EDIT. +*/ + +package executor + +import ( + "flag" + "os" + + "codeflow.dananglin.me.uk/apollo/enbas/internal/config" + internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" + "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" + "codeflow.dananglin.me.uk/apollo/enbas/internal/usage" +) + +func Execute() error { + var ( + configDir string + noColorFlag internalFlag.BoolPtrValue + noColor bool + ) + + flag.StringVar(&configDir, "config-dir", "", "The path to your configuration directory") + flag.Var(&noColorFlag, "no-color", "Set to true to disable ANSI colour output when displaying text on screen") + + flag.Usage = usage.AppUsageFunc() + + flag.Parse() + + if flag.NArg() < 1 { + flag.Usage() + + return nil + } + + if noColorFlag.Value != nil { + noColor = *noColorFlag.Value + } else if os.Getenv("NO_COLOR") != "" { + noColor = true + } + + command := flag.Arg(0) + args := flag.Args()[1:] + + executorMap := map[string]func(string, bool, []string) error{ + "accept": ExecuteAcceptCommand, + "add": ExecuteAddCommand, + "block": ExecuteBlockCommand, + "create": ExecuteCreateCommand, + "delete": ExecuteDeleteCommand, + "edit": ExecuteEditCommand, + "follow": ExecuteFollowCommand, + "init": ExecuteInitCommand, + "login": ExecuteLoginCommand, + "mute": ExecuteMuteCommand, + "reject": ExecuteRejectCommand, + "remove": ExecuteRemoveCommand, + "show": ExecuteShowCommand, + "switch": ExecuteSwitchCommand, + "unblock": ExecuteUnblockCommand, + "unfollow": ExecuteUnfollowCommand, + "unmute": ExecuteUnmuteCommand, + "version": ExecuteVersionCommand, + "whoami": ExecuteWhoamiCommand, + } + + executorFunc, ok := executorMap[command] + if !ok { + err := UnknownCommandError{command: command} + printer.NewPrinter(noColor, "", 0).PrintFailure("Error: " + err.Error()) + + return err + } + + return executorFunc(configDir, noColor, args) +} + +// AcceptExecutor is the executor for the accept command. +type AcceptExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + resourceType string + configDir string +} + +// ExecuteAcceptCommand initialises and runs the executor for the accept command. +func ExecuteAcceptCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := AcceptExecutor{ + FlagSet: flag.NewFlagSet("accept", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(accept) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(accept) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(accept) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// AddExecutor is the executor for the add command. +type AddExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountNames internalFlag.StringSliceValue + content string + listID string + statusID string + toResourceType string + resourceType string + votes internalFlag.IntSliceValue + configDir string +} + +// ExecuteAddCommand initialises and runs the executor for the add command. +func ExecuteAddCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := AddExecutor{ + FlagSet: flag.NewFlagSet("add", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountNames: internalFlag.NewStringSliceValue(), + votes: internalFlag.NewIntSliceValue(), + } + + 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.StringVar(&exe.content, "content", "", "The content of the created resource") + exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") + exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") + exe.StringVar(&exe.toResourceType, "to", "", "The resource type to action the target resource to (e.g. status)") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + exe.Var(&exe.votes, "vote", "Add a vote to an option in a poll") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(add) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(add) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(add) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// BlockExecutor is the executor for the block command. +type BlockExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + resourceType string + configDir string +} + +// ExecuteBlockCommand initialises and runs the executor for the block command. +func ExecuteBlockCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := BlockExecutor{ + FlagSet: flag.NewFlagSet("block", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(block) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(block) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(block) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// CreateExecutor is the executor for the create command. +type CreateExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + addPoll bool + attachmentIDs internalFlag.StringSliceValue + content string + contentType string + federated bool + likeable bool + replyable bool + boostable bool + inReplyTo string + language string + listRepliesPolicy string + listTitle string + mediaDescriptions internalFlag.StringSliceValue + mediaFocusValues internalFlag.StringSliceValue + mediaFiles internalFlag.StringSliceValue + pollAllowsMultipleChoices bool + pollExpiresIn internalFlag.TimeDurationValue + pollHidesVoteCounts bool + pollOptions internalFlag.StringSliceValue + sensitive internalFlag.BoolPtrValue + summary string + resourceType string + visibility string + configDir string +} + +// ExecuteCreateCommand initialises and runs the executor for the create command. +func ExecuteCreateCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := CreateExecutor{ + FlagSet: flag.NewFlagSet("create", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + attachmentIDs: internalFlag.NewStringSliceValue(), + mediaDescriptions: internalFlag.NewStringSliceValue(), + mediaFocusValues: internalFlag.NewStringSliceValue(), + mediaFiles: internalFlag.NewStringSliceValue(), + pollExpiresIn: internalFlag.NewTimeDurationValue(), + pollOptions: internalFlag.NewStringSliceValue(), + sensitive: internalFlag.NewBoolPtrValue(), + } + + 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.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment") + exe.StringVar(&exe.content, "content", "", "The content of the created resource") + exe.StringVar(&exe.contentType, "content-type", "plain", "The type that the contents should be parsed from (valid values are plain and markdown)") + exe.BoolVar(&exe.federated, "enable-federation", true, "Set to true to federate the status beyond the local timelines") + exe.BoolVar(&exe.likeable, "enable-likes", true, "Set to true to allow the status to be liked (favourited)") + exe.BoolVar(&exe.replyable, "enable-replies", true, "Set to true to allow viewers to reply to the status") + exe.BoolVar(&exe.boostable, "enable-reposts", true, "Set to true to allow the status to be reposted (boosted) by others") + exe.StringVar(&exe.inReplyTo, "in-reply-to", "", "The ID of the status that you want to reply to") + exe.StringVar(&exe.language, "language", "", "The ISO 639 language code for this status") + exe.StringVar(&exe.listRepliesPolicy, "list-replies-policy", "list", "The replies policy of the list") + exe.StringVar(&exe.listTitle, "list-title", "", "The title of the list") + exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment which will be used as the alt-text") + exe.Var(&exe.mediaFocusValues, "media-focus", "The focus of the media file") + exe.Var(&exe.mediaFiles, "media-file", "The path to the media file") + exe.BoolVar(&exe.pollAllowsMultipleChoices, "poll-allows-multiple-choices", false, "Set to true to allow viewers to make multiple choices in the poll") + exe.Var(&exe.pollExpiresIn, "poll-expires-in", "The duration in which the poll is open for") + exe.BoolVar(&exe.pollHidesVoteCounts, "poll-hides-vote-counts", false, "Set to true to hide the vote count until the poll is closed") + exe.Var(&exe.pollOptions, "poll-option", "A poll option. Use this multiple times to set multiple options") + exe.Var(&exe.sensitive, "sensitive", "Set to true if the status should be marked as sensitive") + exe.StringVar(&exe.summary, "summary", "", "The summary of the status (a.k.a the subject, spoiler text or content warning)") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + exe.StringVar(&exe.visibility, "visibility", "", "The visibility of the posted status") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(create) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(create) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(create) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// DeleteExecutor is the executor for the delete command. +type DeleteExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + listID string + saveText bool + statusID string + resourceType string + configDir string +} + +// ExecuteDeleteCommand initialises and runs the executor for the delete command. +func ExecuteDeleteCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := DeleteExecutor{ + FlagSet: flag.NewFlagSet("delete", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + } + + 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.BoolVar(&exe.saveText, "save-text", false, "Set to true to save the text of the deleted status") + exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(delete) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(delete) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(delete) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// EditExecutor is the executor for the edit command. +type EditExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + attachmentIDs internalFlag.StringSliceValue + listID string + listTitle string + listRepliesPolicy string + mediaDescriptions internalFlag.StringSliceValue + mediaFocusValues internalFlag.StringSliceValue + resourceType string + configDir string +} + +// ExecuteEditCommand initialises and runs the executor for the edit command. +func ExecuteEditCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := EditExecutor{ + FlagSet: flag.NewFlagSet("edit", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + attachmentIDs: internalFlag.NewStringSliceValue(), + mediaDescriptions: internalFlag.NewStringSliceValue(), + mediaFocusValues: internalFlag.NewStringSliceValue(), + } + + exe.Usage = usage.ExecutorUsageFunc("edit", "Edit a specific resource", exe.FlagSet) + + exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment") + 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.listRepliesPolicy, "list-replies-policy", "", "The replies policy of the list") + exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment which will be used as the alt-text") + exe.Var(&exe.mediaFocusValues, "media-focus", "The focus of the media file") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(edit) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(edit) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(edit) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// FollowExecutor is the executor for the follow command. +type FollowExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + notify bool + showReposts bool + resourceType string + configDir string +} + +// ExecuteFollowCommand initialises and runs the executor for the follow command. +func ExecuteFollowCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := FollowExecutor{ + FlagSet: flag.NewFlagSet("follow", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.BoolVar(&exe.notify, "notify", false, "Get notifications from statuses from the account you want to follow") + exe.BoolVar(&exe.showReposts, "show-reposts", true, "Show reposts from the account you want to follow") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(follow) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(follow) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(follow) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// InitExecutor is the executor for the init command. +type InitExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + configDir string +} + +// ExecuteInitCommand initialises and runs the executor for the init command. +func ExecuteInitCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := InitExecutor{ + FlagSet: flag.NewFlagSet("init", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + } + + exe.Usage = usage.ExecutorUsageFunc("init", "Creates a new configuration file in the specified configuration directory", exe.FlagSet) + + // Create the printer for the executor. + exe.printer = printer.NewPrinter(noColor, "", 0) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(init) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(init) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// LoginExecutor is the executor for the login command. +type LoginExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + instance string + configDir string +} + +// ExecuteLoginCommand initialises and runs the executor for the login command. +func ExecuteLoginCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := LoginExecutor{ + FlagSet: flag.NewFlagSet("login", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + } + + 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") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(login) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(login) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(login) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// MuteExecutor is the executor for the mute command. +type MuteExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + muteDuration internalFlag.TimeDurationValue + muteNotifications bool + statusID string + resourceType string + configDir string +} + +// ExecuteMuteCommand initialises and runs the executor for the mute command. +func ExecuteMuteCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := MuteExecutor{ + FlagSet: flag.NewFlagSet("mute", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + muteDuration: internalFlag.NewTimeDurationValue(), + } + + 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.muteDuration, "mute-duration", "Specify how long the mute should last for. To mute indefinitely, set this to 0s") + exe.BoolVar(&exe.muteNotifications, "mute-notifications", false, "Set to true to mute notifications as well as posts") + exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(mute) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(mute) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(mute) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// RejectExecutor is the executor for the reject command. +type RejectExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + resourceType string + configDir string +} + +// ExecuteRejectCommand initialises and runs the executor for the reject command. +func ExecuteRejectCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := RejectExecutor{ + FlagSet: flag.NewFlagSet("reject", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(reject) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(reject) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(reject) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// RemoveExecutor is the executor for the remove command. +type RemoveExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountNames internalFlag.StringSliceValue + fromResourceType string + listID string + statusID string + resourceType string + configDir string +} + +// ExecuteRemoveCommand initialises and runs the executor for the remove command. +func ExecuteRemoveCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := RemoveExecutor{ + FlagSet: flag.NewFlagSet("remove", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountNames: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.fromResourceType, "from", "", "The resource type to action the target resource from (e.g. status)") + exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") + exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(remove) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(remove) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(remove) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// ShowExecutor is the executor for the show command. +type ShowExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + getAllImages bool + getAllVideos bool + attachmentIDs internalFlag.StringSliceValue + showInBrowser bool + excludeBoosts bool + excludeReplies bool + fromResourceType string + limit int + listID string + myAccount bool + onlyMedia bool + onlyPinned bool + onlyPublic bool + showUserPreferences bool + showStatuses bool + skipAccountRelationship bool + statusID string + timelineCategory string + tag string + resourceType string + configDir string +} + +// ExecuteShowCommand initialises and runs the executor for the show command. +func ExecuteShowCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := ShowExecutor{ + FlagSet: flag.NewFlagSet("show", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + attachmentIDs: internalFlag.NewStringSliceValue(), + } + + 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.BoolVar(&exe.getAllImages, "all-images", false, "Set to true to show all images from a status") + exe.BoolVar(&exe.getAllVideos, "all-videos", false, "Set to true to show all videos from a status") + exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment") + exe.BoolVar(&exe.showInBrowser, "browser", false, "Set to true to view in the your favourite browser") + exe.BoolVar(&exe.excludeBoosts, "exclude-boosts", false, "Set to true to exclude statuses that are boosts of another status") + exe.BoolVar(&exe.excludeReplies, "exclude-replies", false, "Set to true to exclude statuses that are a reply to another status") + exe.StringVar(&exe.fromResourceType, "from", "", "The resource type to action the target resource from (e.g. status)") + exe.IntVar(&exe.limit, "limit", 20, "Specify the limit of items to display") + exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") + exe.BoolVar(&exe.myAccount, "my-account", false, "Set to true to specify your account") + exe.BoolVar(&exe.onlyMedia, "only-media", false, "Set to true to show only the statuses with media attachments") + exe.BoolVar(&exe.onlyPinned, "only-pinned", false, "Set to true to show only the account's pinned statuses") + exe.BoolVar(&exe.onlyPublic, "only-public", false, "Set to true to show only the account's public posts") + exe.BoolVar(&exe.showUserPreferences, "show-preferences", false, "Set to true to view your posting preferences when viewing your account information") + exe.BoolVar(&exe.showStatuses, "show-statuses", false, "Set to true to view the statuses created from the account you are viewing") + exe.BoolVar(&exe.skipAccountRelationship, "skip-relationship", false, "Set to true to skip showing your relationship to the account that you are viewing") + exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") + exe.StringVar(&exe.timelineCategory, "timeline-category", "home", "The timeline category") + exe.StringVar(&exe.tag, "tag", "", "The name of the tag") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(show) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(show) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(show) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// SwitchExecutor is the executor for the switch command. +type SwitchExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + to string + configDir string +} + +// ExecuteSwitchCommand initialises and runs the executor for the switch command. +func ExecuteSwitchCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := SwitchExecutor{ + FlagSet: flag.NewFlagSet("switch", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.to, "to", "", "The resource type to action the target resource to (e.g. status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(switch) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(switch) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(switch) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// UnblockExecutor is the executor for the unblock command. +type UnblockExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + resourceType string + configDir string +} + +// ExecuteUnblockCommand initialises and runs the executor for the unblock command. +func ExecuteUnblockCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := UnblockExecutor{ + FlagSet: flag.NewFlagSet("unblock", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(unblock) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(unblock) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(unblock) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// UnfollowExecutor is the executor for the unfollow command. +type UnfollowExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + resourceType string + configDir string +} + +// ExecuteUnfollowCommand initialises and runs the executor for the unfollow command. +func ExecuteUnfollowCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := UnfollowExecutor{ + FlagSet: flag.NewFlagSet("unfollow", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(unfollow) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(unfollow) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(unfollow) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// UnmuteExecutor is the executor for the unmute command. +type UnmuteExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName internalFlag.StringSliceValue + statusID string + resourceType string + configDir string +} + +// ExecuteUnmuteCommand initialises and runs the executor for the unmute command. +func ExecuteUnmuteCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := UnmuteExecutor{ + FlagSet: flag.NewFlagSet("unmute", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + accountName: internalFlag.NewStringSliceValue(), + } + + 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.StringVar(&exe.statusID, "status-id", "", "The ID of the status") + exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(unmute) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(unmute) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(unmute) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// VersionExecutor is the executor for the version command. +type VersionExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + full bool + configDir string +} + +// ExecuteVersionCommand initialises and runs the executor for the version command. +func ExecuteVersionCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := VersionExecutor{ + FlagSet: flag.NewFlagSet("version", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + } + + 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") + + // Create the printer for the executor. + exe.printer = printer.NewPrinter(noColor, "", 0) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(version) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(version) execution error: " + err.Error() + ".") + + return err + } + + return nil +} + +// WhoamiExecutor is the executor for the whoami command. +type WhoamiExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + configDir string +} + +// ExecuteWhoamiCommand initialises and runs the executor for the whoami command. +func ExecuteWhoamiCommand( + configDir string, + noColor bool, + args []string, +) error { + exe := WhoamiExecutor{ + FlagSet: flag.NewFlagSet("whoami", flag.ExitOnError), + printer: nil, + config: nil, + configDir: configDir, + } + + exe.Usage = usage.ExecutorUsageFunc("whoami", "Prints the account that you are currently logged into", exe.FlagSet) + + // Load the configuration from file. + exeConfig, err := config.NewConfigFromFile(exe.configDir) + if err != nil { + tempPrinter := printer.NewPrinter(noColor, "", 0) + tempPrinter.PrintFailure("(whoami) unable to load configuration: " + err.Error() + ".") + + return err + } + exe.config = exeConfig + + // Create the printer for the executor. + exe.printer = printer.NewPrinter( + noColor, + exe.config.Integrations.Pager, + exe.config.LineWrapMaxWidth, + ) + + // Parse the remaining arguments. + if err := exe.Parse(args); err != nil { + exe.printer.PrintFailure("(whoami) flag parsing error: " + err.Error() + ".") + + return err + } + + // Run the executor. + if err := exe.Execute(); err != nil { + exe.printer.PrintFailure("(whoami) execution error: " + err.Error() + ".") + + return err + } + + return nil +} diff --git a/internal/executor/executors.go b/internal/executor/executors.go deleted file mode 100644 index 5e92528..0000000 --- a/internal/executor/executors.go +++ /dev/null @@ -1,664 +0,0 @@ -/* - This file is generated by the enbas-codegen - DO NOT EDIT. -*/ - -package executor - -import ( - "flag" - - "codeflow.dananglin.me.uk/apollo/enbas/internal/config" - internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag" - "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" - "codeflow.dananglin.me.uk/apollo/enbas/internal/usage" -) - -type Executor interface { - Name() string - Parse(args []string) error - Execute() error -} - -// AcceptExecutor is the executor for the accept command. -type AcceptExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - resourceType string -} - -func NewAcceptExecutor( - printer *printer.Printer, - config *config.Config, -) *AcceptExecutor { - exe := AcceptExecutor{ - FlagSet: flag.NewFlagSet("accept", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// AddExecutor is the executor for the add command. -type AddExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountNames internalFlag.StringSliceValue - content string - listID string - statusID string - toResourceType string - resourceType string - votes internalFlag.IntSliceValue -} - -func NewAddExecutor( - printer *printer.Printer, - config *config.Config, -) *AddExecutor { - exe := AddExecutor{ - FlagSet: flag.NewFlagSet("add", flag.ExitOnError), - printer: printer, - config: config, - accountNames: internalFlag.NewStringSliceValue(), - votes: internalFlag.NewIntSliceValue(), - } - - 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.StringVar(&exe.content, "content", "", "The content of the created resource") - exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") - exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") - exe.StringVar(&exe.toResourceType, "to", "", "The resource type to action the target resource to (e.g. status)") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - exe.Var(&exe.votes, "vote", "Add a vote to an option in a poll") - - return &exe -} - -// BlockExecutor is the executor for the block command. -type BlockExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - resourceType string -} - -func NewBlockExecutor( - printer *printer.Printer, - config *config.Config, -) *BlockExecutor { - exe := BlockExecutor{ - FlagSet: flag.NewFlagSet("block", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// CreateExecutor is the executor for the create command. -type CreateExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - addPoll bool - attachmentIDs internalFlag.StringSliceValue - content string - contentType string - federated bool - likeable bool - replyable bool - boostable bool - inReplyTo string - language string - listRepliesPolicy string - listTitle string - mediaDescriptions internalFlag.StringSliceValue - mediaFocusValues internalFlag.StringSliceValue - mediaFiles internalFlag.StringSliceValue - pollAllowsMultipleChoices bool - pollExpiresIn internalFlag.TimeDurationValue - pollHidesVoteCounts bool - pollOptions internalFlag.StringSliceValue - sensitive internalFlag.BoolPtrValue - summary string - resourceType string - visibility string -} - -func NewCreateExecutor( - printer *printer.Printer, - config *config.Config, -) *CreateExecutor { - exe := CreateExecutor{ - FlagSet: flag.NewFlagSet("create", flag.ExitOnError), - printer: printer, - config: config, - attachmentIDs: internalFlag.NewStringSliceValue(), - mediaDescriptions: internalFlag.NewStringSliceValue(), - mediaFocusValues: internalFlag.NewStringSliceValue(), - mediaFiles: internalFlag.NewStringSliceValue(), - pollExpiresIn: internalFlag.NewTimeDurationValue(), - pollOptions: internalFlag.NewStringSliceValue(), - sensitive: internalFlag.NewBoolPtrValue(), - } - - 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.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment") - exe.StringVar(&exe.content, "content", "", "The content of the created resource") - exe.StringVar(&exe.contentType, "content-type", "plain", "The type that the contents should be parsed from (valid values are plain and markdown)") - exe.BoolVar(&exe.federated, "enable-federation", true, "Set to true to federate the status beyond the local timelines") - exe.BoolVar(&exe.likeable, "enable-likes", true, "Set to true to allow the status to be liked (favourited)") - exe.BoolVar(&exe.replyable, "enable-replies", true, "Set to true to allow viewers to reply to the status") - exe.BoolVar(&exe.boostable, "enable-reposts", true, "Set to true to allow the status to be reposted (boosted) by others") - exe.StringVar(&exe.inReplyTo, "in-reply-to", "", "The ID of the status that you want to reply to") - exe.StringVar(&exe.language, "language", "", "The ISO 639 language code for this status") - exe.StringVar(&exe.listRepliesPolicy, "list-replies-policy", "list", "The replies policy of the list") - exe.StringVar(&exe.listTitle, "list-title", "", "The title of the list") - exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment which will be used as the alt-text") - exe.Var(&exe.mediaFocusValues, "media-focus", "The focus of the media file") - exe.Var(&exe.mediaFiles, "media-file", "The path to the media file") - exe.BoolVar(&exe.pollAllowsMultipleChoices, "poll-allows-multiple-choices", false, "Set to true to allow viewers to make multiple choices in the poll") - exe.Var(&exe.pollExpiresIn, "poll-expires-in", "The duration in which the poll is open for") - exe.BoolVar(&exe.pollHidesVoteCounts, "poll-hides-vote-counts", false, "Set to true to hide the vote count until the poll is closed") - exe.Var(&exe.pollOptions, "poll-option", "A poll option. Use this multiple times to set multiple options") - exe.Var(&exe.sensitive, "sensitive", "Set to true if the status should be marked as sensitive") - exe.StringVar(&exe.summary, "summary", "", "The summary of the status (a.k.a the subject, spoiler text or content warning)") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - exe.StringVar(&exe.visibility, "visibility", "", "The visibility of the posted status") - - return &exe -} - -// DeleteExecutor is the executor for the delete command. -type DeleteExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - listID string - saveText bool - statusID string - resourceType string -} - -func NewDeleteExecutor( - printer *printer.Printer, - config *config.Config, -) *DeleteExecutor { - exe := DeleteExecutor{ - FlagSet: flag.NewFlagSet("delete", flag.ExitOnError), - printer: printer, - config: config, - } - - 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.BoolVar(&exe.saveText, "save-text", false, "Set to true to save the text of the deleted status") - exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// EditExecutor is the executor for the edit command. -type EditExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - attachmentIDs internalFlag.StringSliceValue - listID string - listTitle string - listRepliesPolicy string - mediaDescriptions internalFlag.StringSliceValue - mediaFocusValues internalFlag.StringSliceValue - resourceType string -} - -func NewEditExecutor( - printer *printer.Printer, - config *config.Config, -) *EditExecutor { - exe := EditExecutor{ - FlagSet: flag.NewFlagSet("edit", flag.ExitOnError), - printer: printer, - config: config, - attachmentIDs: internalFlag.NewStringSliceValue(), - mediaDescriptions: internalFlag.NewStringSliceValue(), - mediaFocusValues: internalFlag.NewStringSliceValue(), - } - - exe.Usage = usage.ExecutorUsageFunc("edit", "Edit a specific resource", exe.FlagSet) - - exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment") - 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.listRepliesPolicy, "list-replies-policy", "", "The replies policy of the list") - exe.Var(&exe.mediaDescriptions, "media-description", "The description of the media attachment which will be used as the alt-text") - exe.Var(&exe.mediaFocusValues, "media-focus", "The focus of the media file") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// FollowExecutor is the executor for the follow command. -type FollowExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - notify bool - showReposts bool - resourceType string -} - -func NewFollowExecutor( - printer *printer.Printer, - config *config.Config, -) *FollowExecutor { - exe := FollowExecutor{ - FlagSet: flag.NewFlagSet("follow", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.BoolVar(&exe.notify, "notify", false, "Get notifications from statuses from the account you want to follow") - exe.BoolVar(&exe.showReposts, "show-reposts", true, "Show reposts from the account you want to follow") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// InitExecutor is the executor for the init command. -type InitExecutor struct { - *flag.FlagSet - printer *printer.Printer - configDir string -} - -func NewInitExecutor( - printer *printer.Printer, - configDir string, -) *InitExecutor { - exe := InitExecutor{ - FlagSet: flag.NewFlagSet("init", flag.ExitOnError), - printer: printer, - configDir: configDir, - } - - exe.Usage = usage.ExecutorUsageFunc("init", "Creates a new configuration file in the specified configuration directory", exe.FlagSet) - - return &exe -} - -// LoginExecutor is the executor for the login command. -type LoginExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - instance string -} - -func NewLoginExecutor( - printer *printer.Printer, - config *config.Config, -) *LoginExecutor { - exe := LoginExecutor{ - FlagSet: flag.NewFlagSet("login", flag.ExitOnError), - printer: printer, - config: config, - } - - 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") - - return &exe -} - -// MuteExecutor is the executor for the mute command. -type MuteExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - muteDuration internalFlag.TimeDurationValue - muteNotifications bool - statusID string - resourceType string -} - -func NewMuteExecutor( - printer *printer.Printer, - config *config.Config, -) *MuteExecutor { - exe := MuteExecutor{ - FlagSet: flag.NewFlagSet("mute", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - muteDuration: internalFlag.NewTimeDurationValue(), - } - - 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.muteDuration, "mute-duration", "Specify how long the mute should last for. To mute indefinitely, set this to 0s") - exe.BoolVar(&exe.muteNotifications, "mute-notifications", false, "Set to true to mute notifications as well as posts") - exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// RejectExecutor is the executor for the reject command. -type RejectExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - resourceType string -} - -func NewRejectExecutor( - printer *printer.Printer, - config *config.Config, -) *RejectExecutor { - exe := RejectExecutor{ - FlagSet: flag.NewFlagSet("reject", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// RemoveExecutor is the executor for the remove command. -type RemoveExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountNames internalFlag.StringSliceValue - fromResourceType string - listID string - statusID string - resourceType string -} - -func NewRemoveExecutor( - printer *printer.Printer, - config *config.Config, -) *RemoveExecutor { - exe := RemoveExecutor{ - FlagSet: flag.NewFlagSet("remove", flag.ExitOnError), - printer: printer, - config: config, - accountNames: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.fromResourceType, "from", "", "The resource type to action the target resource from (e.g. status)") - exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") - exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// ShowExecutor is the executor for the show command. -type ShowExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - getAllImages bool - getAllVideos bool - attachmentIDs internalFlag.StringSliceValue - showInBrowser bool - excludeBoosts bool - excludeReplies bool - fromResourceType string - limit int - listID string - myAccount bool - onlyMedia bool - onlyPinned bool - onlyPublic bool - showUserPreferences bool - showStatuses bool - skipAccountRelationship bool - statusID string - timelineCategory string - tag string - resourceType string -} - -func NewShowExecutor( - printer *printer.Printer, - config *config.Config, -) *ShowExecutor { - exe := ShowExecutor{ - FlagSet: flag.NewFlagSet("show", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - attachmentIDs: internalFlag.NewStringSliceValue(), - } - - 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.BoolVar(&exe.getAllImages, "all-images", false, "Set to true to show all images from a status") - exe.BoolVar(&exe.getAllVideos, "all-videos", false, "Set to true to show all videos from a status") - exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment") - exe.BoolVar(&exe.showInBrowser, "browser", false, "Set to true to view in the your favourite browser") - exe.BoolVar(&exe.excludeBoosts, "exclude-boosts", false, "Set to true to exclude statuses that are boosts of another status") - exe.BoolVar(&exe.excludeReplies, "exclude-replies", false, "Set to true to exclude statuses that are a reply to another status") - exe.StringVar(&exe.fromResourceType, "from", "", "The resource type to action the target resource from (e.g. status)") - exe.IntVar(&exe.limit, "limit", 20, "Specify the limit of items to display") - exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question") - exe.BoolVar(&exe.myAccount, "my-account", false, "Set to true to specify your account") - exe.BoolVar(&exe.onlyMedia, "only-media", false, "Set to true to show only the statuses with media attachments") - exe.BoolVar(&exe.onlyPinned, "only-pinned", false, "Set to true to show only the account's pinned statuses") - exe.BoolVar(&exe.onlyPublic, "only-public", false, "Set to true to show only the account's public posts") - exe.BoolVar(&exe.showUserPreferences, "show-preferences", false, "Set to true to view your posting preferences when viewing your account information") - exe.BoolVar(&exe.showStatuses, "show-statuses", false, "Set to true to view the statuses created from the account you are viewing") - exe.BoolVar(&exe.skipAccountRelationship, "skip-relationship", false, "Set to true to skip showing your relationship to the account that you are viewing") - exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status") - exe.StringVar(&exe.timelineCategory, "timeline-category", "home", "The timeline category") - exe.StringVar(&exe.tag, "tag", "", "The name of the tag") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// SwitchExecutor is the executor for the switch command. -type SwitchExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - to string -} - -func NewSwitchExecutor( - printer *printer.Printer, - config *config.Config, -) *SwitchExecutor { - exe := SwitchExecutor{ - FlagSet: flag.NewFlagSet("switch", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.to, "to", "", "The resource type to action the target resource to (e.g. status)") - - return &exe -} - -// UnblockExecutor is the executor for the unblock command. -type UnblockExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - resourceType string -} - -func NewUnblockExecutor( - printer *printer.Printer, - config *config.Config, -) *UnblockExecutor { - exe := UnblockExecutor{ - FlagSet: flag.NewFlagSet("unblock", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// UnfollowExecutor is the executor for the unfollow command. -type UnfollowExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - resourceType string -} - -func NewUnfollowExecutor( - printer *printer.Printer, - config *config.Config, -) *UnfollowExecutor { - exe := UnfollowExecutor{ - FlagSet: flag.NewFlagSet("unfollow", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// UnmuteExecutor is the executor for the unmute command. -type UnmuteExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config - accountName internalFlag.StringSliceValue - statusID string - resourceType string -} - -func NewUnmuteExecutor( - printer *printer.Printer, - config *config.Config, -) *UnmuteExecutor { - exe := UnmuteExecutor{ - FlagSet: flag.NewFlagSet("unmute", flag.ExitOnError), - printer: printer, - config: config, - accountName: internalFlag.NewStringSliceValue(), - } - - 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.StringVar(&exe.statusID, "status-id", "", "The ID of the status") - exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") - - return &exe -} - -// VersionExecutor is the executor for the version command. -type VersionExecutor struct { - *flag.FlagSet - printer *printer.Printer - full bool -} - -func NewVersionExecutor( - printer *printer.Printer, -) *VersionExecutor { - exe := VersionExecutor{ - FlagSet: flag.NewFlagSet("version", flag.ExitOnError), - printer: printer, - } - - 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") - - return &exe -} - -// WhoamiExecutor is the executor for the whoami command. -type WhoamiExecutor struct { - *flag.FlagSet - printer *printer.Printer - config *config.Config -} - -func NewWhoamiExecutor( - printer *printer.Printer, - config *config.Config, -) *WhoamiExecutor { - exe := WhoamiExecutor{ - FlagSet: flag.NewFlagSet("whoami", flag.ExitOnError), - printer: printer, - config: config, - } - - exe.Usage = usage.ExecutorUsageFunc("whoami", "Prints the account that you are currently logged into", exe.FlagSet) - - return &exe -} diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index 54a798b..3b9f386 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -208,7 +208,9 @@ "commands": { "accept": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "type", "fieldName": "resourceType", "default": "" } @@ -218,7 +220,9 @@ "usePrinter": true }, "add": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name", "fieldName": "accountNames" }, { "flag": "content", "default": "" }, @@ -233,7 +237,9 @@ "usePrinter": true }, "block": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "type", "fieldName": "resourceType", "default": "" } @@ -243,7 +249,9 @@ "usePrinter": true }, "create": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "add-poll", "default": "false" }, { "flag": "attachment-id", "fieldName": "attachmentIDs" }, @@ -274,7 +282,9 @@ "usePrinter": true }, "delete": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "list-id", "fieldName": "listID", "default": ""}, { "flag": "save-text", "default": "false" }, @@ -286,7 +296,9 @@ "usePrinter": true }, "edit": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "attachment-id", "fieldName": "attachmentIDs" }, { "flag": "list-id", "fieldName": "listID", "default": ""}, @@ -301,7 +313,9 @@ "usePrinter": true }, "follow": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "notify", "default": "false" }, @@ -318,11 +332,13 @@ ], "flags": [], "summary": "Creates a new configuration file in the specified configuration directory", - "useConfig": true, + "useConfig": false, "usePrinter": true }, "login": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "instance", "default": "" } ], @@ -331,7 +347,9 @@ "usePrinter": true }, "mute": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "mute-duration" }, @@ -344,7 +362,9 @@ "usePrinter": true }, "reject": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "type", "fieldName": "resourceType", "default": "" } @@ -354,7 +374,9 @@ "usePrinter": true }, "remove": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name", "fieldName": "accountNames" }, { "flag": "from", "fieldName": "fromResourceType", "default": "" }, @@ -367,7 +389,9 @@ "usePrinter": true }, "show": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "all-images", "fieldName": "getAllImages", "default": "false" }, @@ -396,7 +420,9 @@ "usePrinter": true }, "switch": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "to", "default": "" } @@ -406,7 +432,9 @@ "usePrinter": true }, "unblock": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "type", "fieldName": "resourceType", "default": "" } @@ -416,7 +444,9 @@ "usePrinter": true }, "unfollow": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "type", "fieldName": "resourceType", "default": "" } @@ -426,7 +456,9 @@ "usePrinter": true }, "unmute": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "account-name" }, { "flag": "status-id", "fieldName": "statusID", "default": "" }, @@ -437,7 +469,9 @@ "usePrinter": true }, "version": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [ { "flag": "full", "default": "false" } ], @@ -446,7 +480,9 @@ "usePrinter": true }, "whoami": { - "additionalFields": [], + "additionalFields": [ + { "name": "configDir", "type": "string"} + ], "flags": [], "summary": "Prints the account that you are currently logged into", "useConfig": true,