From fe52a991db9f0ea823364bd80a3a257a2d8a062f Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sun, 11 Aug 2024 11:49:47 +0100 Subject: [PATCH] checkpoint: add show to the schema --- cmd/enbas-cli-generators/templates.go | 4 + cmd/enbas/main.go | 2 - internal/executor/executors.go | 82 ++++++++++++++++++++ internal/executor/flags.go | 44 ++++------- internal/executor/show.go | 68 ----------------- schema/enbas_cli_schema.json | 106 ++++++++++++++++++++++++++ 6 files changed, 207 insertions(+), 99 deletions(-) diff --git a/cmd/enbas-cli-generators/templates.go b/cmd/enbas-cli-generators/templates.go index 9f825b7..e20870b 100644 --- a/cmd/enbas-cli-generators/templates.go +++ b/cmd/enbas-cli-generators/templates.go @@ -75,12 +75,16 @@ func {{ $new_executor_function_name }}( {{- else if eq $flag_type "bool" -}} {{ print "" }} exe.BoolVar(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ $flag.Default }}, {{ getFlagDescription $flag.Flag | printf "%q" }}) + {{- else if eq $flag_type "int" -}} + {{ print "" }} + exe.IntVar(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ $flag.Default }}, {{ getFlagDescription $flag.Flag | printf "%q" }}) {{- else if customFlagValueType $flag_type -}} {{ print "" }} exe.Var(&exe.{{ flagFieldName $flag }}, {{ printf "%q" $flag.Flag }}, {{ getFlagDescription $flag.Flag | printf "%q" }}) {{- end -}} {{- end -}} {{ print "" }} + {{ print "" }} return &exe } {{ end }} diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index d2c679a..92fc39b 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -160,8 +160,6 @@ func run() error { executor.CommandShow: executor.NewShowExecutor( enbasPrinter, enbasConfig, - executor.CommandShow, - executor.CommandSummaryLookup(executor.CommandShow), ), executor.CommandVersion: executor.NewVersionExecutor( enbasPrinter, diff --git a/internal/executor/executors.go b/internal/executor/executors.go index 8c683b0..dc28933 100644 --- a/internal/executor/executors.go +++ b/internal/executor/executors.go @@ -35,6 +35,7 @@ func NewAcceptExecutor( exe.StringVar(&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 } @@ -61,6 +62,7 @@ func NewBlockExecutor( exe.StringVar(&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 } @@ -126,6 +128,7 @@ func NewCreateExecutor( exe.StringVar(&exe.spoilerText, "spoiler-text", "", "The text to display as the status' warning or subject") 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 } @@ -152,6 +155,7 @@ func NewDeleteExecutor( 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)") + return &exe } @@ -182,6 +186,7 @@ func NewEditExecutor( 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.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + return &exe } @@ -212,6 +217,7 @@ func NewFollowExecutor( 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 } @@ -258,6 +264,7 @@ func NewLoginExecutor( exe.Usage = commandUsageFunc("login", "Logs into an account on GoToSocial", exe.FlagSet) exe.StringVar(&exe.instance, "instance", "", "The instance that you want to log into") + return &exe } @@ -289,6 +296,7 @@ func NewMuteExecutor( 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.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)") + return &exe } @@ -315,6 +323,75 @@ func NewRejectExecutor( exe.StringVar(&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 +} + +// ShowExecutor is the executor for the show command. +type ShowExecutor struct { + *flag.FlagSet + printer *printer.Printer + config *config.Config + accountName string + getAllImages bool + getAllVideos bool + attachmentIDs MultiStringFlagValue + showInBrowser bool + excludeBoosts bool + excludeReplies bool + fromResourceType string + limit int + listID string + myAccount bool + onlyMedia bool + onlyPinned bool + onlyPublic bool + pollID string + 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, + attachmentIDs: NewMultiStringFlagValue(), + } + + exe.Usage = commandUsageFunc("show", "Shows details about a specified resource", exe.FlagSet) + + exe.StringVar(&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", "", "Specify the resource type to action the target resource from") + 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.StringVar(&exe.pollID, "poll-id", "", "The ID of the poll") + 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 } @@ -341,6 +418,7 @@ func NewSwitchExecutor( exe.StringVar(&exe.accountName, "account-name", "", "The name of the account") exe.StringVar(&exe.to, "to", "", "TBC") + return &exe } @@ -367,6 +445,7 @@ func NewUnblockExecutor( exe.StringVar(&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 } @@ -393,6 +472,7 @@ func NewUnfollowExecutor( exe.StringVar(&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 } @@ -419,6 +499,7 @@ func NewUnmuteExecutor( exe.StringVar(&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 } @@ -452,6 +533,7 @@ func NewVersionExecutor( exe.Usage = commandUsageFunc("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 } diff --git a/internal/executor/flags.go b/internal/executor/flags.go index baa17e0..902bfbd 100644 --- a/internal/executor/flags.go +++ b/internal/executor/flags.go @@ -8,35 +8,21 @@ import ( ) const ( - flagAccountName = "account-name" - flagAllImages = "all-images" - flagAllVideos = "all-videos" - flagAttachmentID = "attachment-id" - flagBrowser = "browser" - flagContent = "content" - flagExcludeBoosts = "exclude-boosts" - flagExcludeReplies = "exclude-replies" - flagFrom = "from" - flagFromFile = "from-file" - flagInstance = "instance" - flagLimit = "limit" - flagListID = "list-id" - flagListTitle = "list-title" - flagMyAccount = "my-account" - flagOnlyMedia = "only-media" - flagOnlyPinned = "only-pinned" - flagOnlyPublic = "only-public" - flagPollID = "poll-id" - flagPollOption = "poll-option" - flagSkipRelationship = "skip-relationship" - flagShowPreferences = "show-preferences" - flagShowStatuses = "show-statuses" - flagStatusID = "status-id" - flagTag = "tag" - flagTimelineCategory = "timeline-category" - flagTo = "to" - flagType = "type" - flagVote = "vote" + flagAccountName = "account-name" + flagAttachmentID = "attachment-id" + flagContent = "content" + flagFrom = "from" + flagFromFile = "from-file" + flagInstance = "instance" + flagListID = "list-id" + flagListTitle = "list-title" + flagPollID = "poll-id" + flagPollOption = "poll-option" + flagStatusID = "status-id" + flagTag = "tag" + flagTo = "to" + flagType = "type" + flagVote = "vote" ) type MultiStringFlagValue []string diff --git a/internal/executor/show.go b/internal/executor/show.go index ea1244e..0894506 100644 --- a/internal/executor/show.go +++ b/internal/executor/show.go @@ -1,83 +1,15 @@ package executor import ( - "flag" "fmt" "path/filepath" "codeflow.dananglin.me.uk/apollo/enbas/internal/client" - "codeflow.dananglin.me.uk/apollo/enbas/internal/config" "codeflow.dananglin.me.uk/apollo/enbas/internal/media" "codeflow.dananglin.me.uk/apollo/enbas/internal/model" - "codeflow.dananglin.me.uk/apollo/enbas/internal/printer" "codeflow.dananglin.me.uk/apollo/enbas/internal/utilities" ) -type ShowExecutor struct { - *flag.FlagSet - - printer *printer.Printer - config *config.Config - myAccount bool - excludeBoosts bool - excludeReplies bool - onlyMedia bool - onlyPinned bool - onlyPublic bool - showInBrowser bool - showUserPreferences bool - showStatuses bool - skipAccountRelationship bool - getAllImages bool - getAllVideos bool - resourceType string - accountName string - statusID string - timelineCategory string - listID string - tag string - pollID string - fromResourceType string - limit int - attachmentIDs MultiStringFlagValue -} - -func NewShowExecutor(printer *printer.Printer, config *config.Config, name, summary string) *ShowExecutor { - showExe := ShowExecutor{ - FlagSet: flag.NewFlagSet(name, flag.ExitOnError), - - printer: printer, - config: config, - } - - showExe.BoolVar(&showExe.myAccount, flagMyAccount, false, "Set to true to lookup your account") - showExe.BoolVar(&showExe.skipAccountRelationship, flagSkipRelationship, false, "Set to true to skip showing your relationship to the specified account") - showExe.BoolVar(&showExe.showUserPreferences, flagShowPreferences, false, "Show your preferences") - showExe.BoolVar(&showExe.showInBrowser, flagBrowser, false, "Set to true to view in the browser") - showExe.BoolVar(&showExe.showStatuses, flagShowStatuses, false, "Set to true to view the statuses created from the specified account") - showExe.BoolVar(&showExe.excludeReplies, flagExcludeReplies, false, "Set to true to exclude statuses that are a reply to another status") - showExe.BoolVar(&showExe.excludeBoosts, flagExcludeBoosts, false, "Set to true to exclude statuses that are boosts of another status") - showExe.BoolVar(&showExe.onlyPinned, flagOnlyPinned, false, "Set to true to show only the account's pinned statuses") - showExe.BoolVar(&showExe.onlyMedia, flagOnlyMedia, false, "Set to true to show only the statuses with media attachments") - showExe.BoolVar(&showExe.onlyPublic, flagOnlyPublic, false, "Set to true to show only the account's public posts") - showExe.BoolVar(&showExe.getAllImages, flagAllImages, false, "Set to true to show all images from a status") - showExe.BoolVar(&showExe.getAllVideos, flagAllVideos, false, "Set to true to show all videos from a status") - showExe.StringVar(&showExe.resourceType, flagType, "", "Specify the type of resource to display") - showExe.StringVar(&showExe.accountName, flagAccountName, "", "Specify the account name in full (username@domain)") - showExe.StringVar(&showExe.statusID, flagStatusID, "", "Specify the ID of the status to display") - showExe.StringVar(&showExe.timelineCategory, flagTimelineCategory, model.TimelineCategoryHome, "Specify the timeline category to view") - showExe.StringVar(&showExe.listID, flagListID, "", "Specify the ID of the list to display") - showExe.StringVar(&showExe.tag, flagTag, "", "Specify the name of the tag to use") - showExe.StringVar(&showExe.pollID, flagPollID, "", "Specify the ID of the poll to display") - showExe.Var(&showExe.attachmentIDs, flagAttachmentID, "Specify the ID of the media attachment to display") - showExe.StringVar(&showExe.fromResourceType, flagFrom, "", "Specify the resource type to view the target resource from (e.g. status for viewing media from, etc)") - showExe.IntVar(&showExe.limit, flagLimit, 20, "Specify the limit of items to display") - - showExe.Usage = commandUsageFunc(name, summary, showExe.FlagSet) - - return &showExe -} - func (s *ShowExecutor) Execute() error { if s.resourceType == "" { return FlagNotSetError{flagText: flagType} diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index 5cb60b6..a07e5ba 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -4,10 +4,26 @@ "type": "string", "description": "The name of the account" }, + "all-images": { + "type": "bool", + "description": "Set to true to show all images from a status" + }, + "all-videos": { + "type": "bool", + "description": "Set to true to show all videos from a status" + }, + "attachment-id": { + "type": "MultiStringFlagValue", + "description": "The ID of the media attachment" + }, "add-poll": { "type": "bool", "description": "Set to true to add a poll when creating a status" }, + "browser": { + "type": "bool", + "description": "Set to true to view in the your favourite browser" + }, "content": { "type": "string", "description": "The content of the created resource" @@ -32,6 +48,18 @@ "type": "bool", "description": "Set to true to allow the status to be reposted (boosted) by others" }, + "exclude-boosts": { + "type": "bool", + "description": "Set to true to exclude statuses that are boosts of another status" + }, + "exclude-replies": { + "type": "bool", + "description": "Set to true to exclude statuses that are a reply to another status" + }, + "from": { + "type": "string", + "description": "Specify the resource type to action the target resource from" + }, "from-file": { "type": "string", "description": "The file path where to read the contents from" @@ -52,6 +80,10 @@ "type": "string", "description": "The ISO 639 language code for this status" }, + "limit": { + "type": "int", + "description": "Specify the limit of items to display" + }, "list-id": { "type": "string", "description": "The ID of the list in question" @@ -72,10 +104,26 @@ "type": "bool", "description": "Set to true to mute notifications as well as posts" }, + "my-account": { + "type": "bool", + "description": "Set to true to specify your account" + }, "notify": { "type": "bool", "description": "Get notifications from statuses from the account you want to follow" }, + "only-media": { + "type": "bool", + "description": "Set to true to show only the statuses with media attachments" + }, + "only-pinned": { + "type": "bool", + "description": "Set to true to show only the account's pinned statuses" + }, + "only-public": { + "type": "bool", + "description": "Set to true to show only the account's public posts" + }, "poll-allows-multiple-choices": { "type": "bool", "description": "Set to true to allow viewers to make multiple choices in the poll" @@ -88,6 +136,10 @@ "type": "bool", "description": "Set to true to hide the vote count until the poll is closed" }, + "poll-id": { + "type": "string", + "description": "The ID of the poll" + }, "poll-option": { "type": "MultiStringFlagValue", "description": "A poll option. Use this multiple times to set multiple options" @@ -96,14 +148,38 @@ "type": "BoolPtrFlagValue", "description": "Set to true if the status should be marked as sensitive" }, + "show-preferences": { + "type": "bool", + "description": "Set to true to view your posting preferences when viewing your account information" + }, "show-reposts": { "type": "bool", "description": "Show reposts from the account you want to follow" }, + "show-statuses": { + "type": "bool", + "description": "Set to true to view the statuses created from the account you are viewing" + }, + "skip-relationship": { + "type": "bool", + "description": "Set to true to skip showing your relationship to the account that you are viewing" + }, "spoiler-text": { "type": "string", "description": "The text to display as the status' warning or subject" }, + "status-id": { + "type": "string", + "description": "The ID of the status" + }, + "tag": { + "type": "string", + "description": "The name of the tag" + }, + "timeline-category": { + "type": "string", + "description": "The timeline category" + }, "type": { "type": "string", "description": "The type of resource you want to action on (e.g. account, status)" @@ -241,6 +317,36 @@ "useConfig": true, "usePrinter": true }, + "show": { + "additionalFields": [], + "flags": [ + { "flag": "account-name", "default": "" }, + { "flag": "all-images", "fieldName": "getAllImages", "default": "false" }, + { "flag": "all-videos", "fieldName": "getAllVideos", "default": "false" }, + { "flag": "attachment-id", "fieldName": "attachmentIDs" }, + { "flag": "browser", "fieldName": "showInBrowser", "default": "false" }, + { "flag": "exclude-boosts", "default": "false" }, + { "flag": "exclude-replies", "default": "false" }, + { "flag": "from", "fieldName": "fromResourceType", "default": "" }, + { "flag": "limit", "default": "20" }, + { "flag": "list-id", "fieldName": "listID", "default": "" }, + { "flag": "my-account", "default": "false" }, + { "flag": "only-media", "default": "false" }, + { "flag": "only-pinned", "default": "false" }, + { "flag": "only-public", "default": "false" }, + { "flag": "poll-id", "fieldName": "pollID", "default": "" }, + { "flag": "show-preferences", "fieldName": "showUserPreferences", "default": "false" }, + { "flag": "show-statuses", "default": "false" }, + { "flag": "skip-relationship", "fieldName": "skipAccountRelationship", "default": "false" }, + { "flag": "status-id", "fieldName": "statusID", "default": "" }, + { "flag": "timeline-category", "default": "home" }, + { "flag": "tag", "default": "" }, + { "flag": "type", "fieldName": "resourceType", "default": "" } + ], + "summary": "Shows details about a specified resource", + "useConfig": true, + "usePrinter": true + }, "switch": { "additionalFields": [], "flags": [