From 8505d1f7ae0236181edab1b34094b05d0a3ecdfe Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 14 Aug 2024 21:44:59 +0100 Subject: [PATCH] checkpoint: updated media attachment flags Updated the flags used for the media attachment stuff. --- internal/executor/create.go | 28 ++++++++++++++++++--- internal/executor/edit.go | 24 ++++++++++++++---- internal/executor/executors.go | 45 ++++++++++++++++++++-------------- schema/enbas_cli_schema.json | 29 +++++++++++++--------- 4 files changed, 87 insertions(+), 39 deletions(-) diff --git a/internal/executor/create.go b/internal/executor/create.go index 7ca483f..c35bbcf 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -168,11 +168,33 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error { } func (c *CreateExecutor) createMediaAttachment(gtsClient *client.Client) error { - if c.fromFile == "" { - return FlagNotSetError{flagText: flagFromFile} + expectedNumValues := 1 + if !c.mediaFiles.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media files: want %d", + expectedNumValues, + ) } - attachment, err := gtsClient.CreateMediaAttachment(c.fromFile, c.description, c.focus) + if !c.mediaDescriptions.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media descriptions: want %d", + expectedNumValues, + ) + } + + if !c.mediaFocusValues.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media focus values: want %d", + expectedNumValues, + ) + } + + attachment, err := gtsClient.CreateMediaAttachment( + c.mediaFiles[0], + c.mediaDescriptions[0], + c.mediaFocusValues[0], + ) if err != nil { return fmt.Errorf("unable to create the media attachment: %w", err) } diff --git a/internal/executor/edit.go b/internal/executor/edit.go index 1dc96b0..996ecd7 100644 --- a/internal/executor/edit.go +++ b/internal/executor/edit.go @@ -65,11 +65,25 @@ func (e *EditExecutor) editList(gtsClient *client.Client) error { } func (e *EditExecutor) editMediaAttachment(gtsClient *client.Client) error { - expectedNumMediaAttachmentIDs := 1 - if !e.attachmentIDs.ExpectedLength(expectedNumMediaAttachmentIDs) { + expectedNumValues := 1 + if !e.attachmentIDs.ExpectedLength(expectedNumValues) { return fmt.Errorf( "received an unexpected number of media attachment IDs: want %d", - expectedNumMediaAttachmentIDs, + expectedNumValues, + ) + } + + if !e.mediaDescriptions.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media descriptions: want %d", + expectedNumValues, + ) + } + + if !e.mediaFocusValues.ExpectedLength(expectedNumValues) { + return fmt.Errorf( + "received an unexpected number of media focus values: want %d", + expectedNumValues, ) } @@ -78,12 +92,12 @@ func (e *EditExecutor) editMediaAttachment(gtsClient *client.Client) error { return fmt.Errorf("unable to get the media attachment: %w", err) } - description := e.description + description := e.mediaDescriptions[0] if description == "" { description = attachment.Description } - focus := e.focus + focus := e.mediaFocusValues[0] if focus == "" { focus = fmt.Sprintf("%f,%f", attachment.Meta.Focus.X, attachment.Meta.Focus.Y) } diff --git a/internal/executor/executors.go b/internal/executor/executors.go index a72b751..be6cf67 100644 --- a/internal/executor/executors.go +++ b/internal/executor/executors.go @@ -124,17 +124,18 @@ type CreateExecutor struct { attachmentIDs internalFlag.StringSliceValue content string contentType string - description string federated bool likeable bool replyable bool boostable bool - focus string fromFile string inReplyTo string language string listRepliesPolicy string listTitle string + mediaDescriptions internalFlag.StringSliceValue + mediaFocusValues internalFlag.StringSliceValue + mediaFiles internalFlag.StringSliceValue pollAllowsMultipleChoices bool pollExpiresIn internalFlag.TimeDurationValue pollHidesVoteCounts bool @@ -150,13 +151,16 @@ func NewCreateExecutor( config *config.Config, ) *CreateExecutor { exe := CreateExecutor{ - FlagSet: flag.NewFlagSet("create", flag.ExitOnError), - printer: printer, - config: config, - attachmentIDs: internalFlag.NewStringSliceValue(), - pollExpiresIn: internalFlag.NewTimeDurationValue(), - pollOptions: internalFlag.NewStringSliceValue(), - sensitive: internalFlag.NewBoolPtrValue(), + 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) @@ -165,17 +169,18 @@ func NewCreateExecutor( 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.StringVar(&exe.description, "description", "", "The description of the media attachment that will be used as the alt-text") 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.focus, "focus", "", "The focus of the media file") exe.StringVar(&exe.fromFile, "from-file", "", "The file path where to read the contents from") 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 that 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") @@ -221,11 +226,11 @@ type EditExecutor struct { printer *printer.Printer config *config.Config attachmentIDs internalFlag.StringSliceValue - description string - focus string listID string listTitle string listRepliesPolicy string + mediaDescriptions internalFlag.StringSliceValue + mediaFocusValues internalFlag.StringSliceValue resourceType string } @@ -234,20 +239,22 @@ func NewEditExecutor( config *config.Config, ) *EditExecutor { exe := EditExecutor{ - FlagSet: flag.NewFlagSet("edit", flag.ExitOnError), - printer: printer, - config: config, - attachmentIDs: internalFlag.NewStringSliceValue(), + 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.description, "description", "", "The description of the media attachment that will be used as the alt-text") - exe.StringVar(&exe.focus, "focus", "", "The focus of the media file") 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 that 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 diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index 9c96abb..85440ec 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -32,10 +32,6 @@ "type": "string", "description": "The type that the contents should be parsed from (valid values are plain and markdown)" }, - "description": { - "type": "string", - "description": "The description of the media attachment that will be used as the alt-text" - }, "enable-federation": { "type": "bool", "description": "Set to true to federate the status beyond the local timelines" @@ -60,10 +56,6 @@ "type": "bool", "description": "Set to true to exclude statuses that are a reply to another status" }, - "focus": { - "type": "string", - "description": "The focus of the media file" - }, "from": { "type": "string", "description": "The resource type to action the target resource from (e.g. status)" @@ -104,6 +96,18 @@ "type": "string", "description": "The replies policy of the list" }, + "media-description": { + "type": "StringSliceValue", + "description": "The description of the media attachment that will be used as the alt-text" + }, + "media-file": { + "type": "StringSliceValue", + "description": "The path to the media file" + }, + "media-focus": { + "type": "StringSliceValue", + "description": "The focus of the media file" + }, "mute-duration": { "type": "TimeDurationValue", "description": "Specify how long the mute should last for. To mute indefinitely, set this to 0s" @@ -245,17 +249,18 @@ { "flag": "attachment-id", "fieldName": "attachmentIDs" }, { "flag": "content", "default": "" }, { "flag": "content-type", "default": "plain" }, - { "flag": "description", "default": "" }, { "flag": "enable-federation", "fieldName": "federated", "default": "true" }, { "flag": "enable-likes", "fieldName": "likeable", "default": "true" }, { "flag": "enable-replies", "fieldName": "replyable", "default": "true" }, { "flag": "enable-reposts", "fieldName": "boostable", "default": "true" }, - { "flag": "focus", "default": "" }, { "flag": "from-file", "default": "" }, { "flag": "in-reply-to", "default": "" }, { "flag": "language", "default": "" }, { "flag": "list-replies-policy", "default": "list" }, { "flag": "list-title", "default": "" }, + { "flag": "media-description", "fieldName": "mediaDescriptions" }, + { "flag": "media-focus", "fieldName": "mediaFocusValues" }, + { "flag": "media-file", "fieldName": "mediaFiles" }, { "flag": "poll-allows-multiple-choices", "default": "false" }, { "flag": "poll-expires-in" }, { "flag": "poll-hides-vote-counts", "default": "false" }, @@ -283,11 +288,11 @@ "additionalFields": [], "flags": [ { "flag": "attachment-id", "fieldName": "attachmentIDs" }, - { "flag": "description", "default": "" }, - { "flag": "focus", "default": "" }, { "flag": "list-id", "fieldName": "listID", "default": ""}, { "flag": "list-title", "default": "" }, { "flag": "list-replies-policy", "default": "" }, + { "flag": "media-description", "fieldName": "mediaDescriptions" }, + { "flag": "media-focus", "fieldName": "mediaFocusValues" }, { "flag": "type", "fieldName": "resourceType", "default": "" } ], "summary": "Edit a specific resource",