From 39d9ef1a381f31559d4d72bd8b21d0ec122de371 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Fri, 16 Aug 2024 19:57:44 +0100 Subject: [PATCH] fix(BREAKING): remove the from-file flag The from-file flag was used to read text from a file for creating statuses. This flag is now removed and replaced with the file@ prefix with the content flag. For example, --from-file status.md is now replaced with --content file@status.md --- docs/manual.md | 5 ++--- internal/executor/add.go | 6 ++---- internal/executor/create.go | 28 +++++++++------------------- internal/executor/errors.go | 15 --------------- internal/executor/executors.go | 2 -- internal/executor/flags.go | 1 - schema/enbas_cli_schema.json | 5 ----- 7 files changed, 13 insertions(+), 49 deletions(-) diff --git a/docs/manual.md b/docs/manual.md index aae11bb..4c94c66 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -461,7 +461,7 @@ Creates a new status. ``` - Create a private status from a file. ``` - enbas create --type status --content-type markdown --visibility private --from-file status.md + enbas create --type status --content-type markdown --visibility private --content file@status.md ``` - Reply to another status. ``` @@ -505,13 +505,12 @@ Creates a new status. |------|------|----------|-------------|---------| | `type` | string | true | The resource you want to create.
Here this should be `status`. | | | `attachment-id` | string | false | The ID of the media attachment to attach to the status.
Use this flag multiple times to attach multiple media. | -| `content` | string | false | The content of the status.
This flag takes precedence over `from-file`.| | +| `content` | string | false | The content of the status.
To read the content from a text file, use the `flag@` prefix followed by the path to the file (e.g. `file@status.md`).| | | `content-type` | string | false | The format that the content is created in.
Valid values are `plain` and `markdown`. | plain | | `enable-reposts` | boolean | false | The status can be reposted (boosted) by others. | true | | `enable-federation` | boolean | false | The status can be federated beyond the local timelines. | true | | `enable-likes` | boolean | false | The status can be liked (favourtied). | true | | `enable-replies` | boolean | false | The status can be replied to. | true | -| `from-file` | string | false | The path to the file where to read the contents of the status from. | | | `in-reply-to` | string | false | The ID of the status that you want to reply to. | | | `language` | string | false | The ISO 639 language code that the status is written in.
If this is not specified then the default language from your posting preferences will be used. | | | `media-file` | string | false | The path to the media file.
Use this flag multiple times to upload multiple media files. | | diff --git a/internal/executor/add.go b/internal/executor/add.go index a66bda1..f18a733 100644 --- a/internal/executor/add.go +++ b/internal/executor/add.go @@ -1,6 +1,7 @@ package executor import ( + "errors" "fmt" "codeflow.dananglin.me.uk/apollo/enbas/internal/client" @@ -108,10 +109,7 @@ func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error { } if a.content == "" { - return EmptyContentError{ - ResourceType: resourceNote, - Hint: "please use --" + flagContent, - } + return errors.New("please add content to the status that you want to create") } if err := gtsClient.SetPrivateNote(accountID, a.content); err != nil { diff --git a/internal/executor/create.go b/internal/executor/create.go index 6e0472a..a49bb09 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -62,7 +62,6 @@ func (c *CreateExecutor) createList(gtsClient *client.Client) error { func (c *CreateExecutor) createStatus(gtsClient *client.Client) error { var ( err error - content string language string visibility string sensitive bool @@ -94,12 +93,12 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error { if descriptionsExists { for ind := 0; ind < expectedLength; ind++ { - content, err := utilities.ReadContents(c.mediaDescriptions[ind]) + mediaDesc, err := utilities.ReadContents(c.mediaDescriptions[ind]) if err != nil { return fmt.Errorf("unable to read the contents from %s: %w", c.mediaDescriptions[ind], err) } - mediaDescriptions[ind] = content + mediaDescriptions[ind] = mediaDesc } } @@ -133,22 +132,13 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error { } } - switch { - case c.content != "": - content = c.content - case c.fromFile != "": - content, err = utilities.ReadTextFile(c.fromFile) - if err != nil { - return fmt.Errorf("unable to get the status contents from %q: %w", c.fromFile, err) - } - default: - if len(attachmentIDs) == 0 { - // TODO: revisit this error type - return EmptyContentError{ - ResourceType: resourceStatus, - Hint: "please use --" + flagContent + " or --" + flagFromFile, - } - } + if c.content == "" && len(attachmentIDs) == 0 { + return errors.New("please add content to the status that you want to create") + } + + content, err := utilities.ReadContents(c.content) + if err != nil { + return fmt.Errorf("unable to read the contents from %s: %w", c.content, err) } numAttachmentIDs := len(attachmentIDs) diff --git a/internal/executor/errors.go b/internal/executor/errors.go index 62e49c3..45edce8 100644 --- a/internal/executor/errors.go +++ b/internal/executor/errors.go @@ -61,21 +61,6 @@ func (e UnsupportedShowOperationError) Error() string { "' is not supported" } -type EmptyContentError struct { - ResourceType string - Hint string -} - -func (e EmptyContentError) Error() string { - message := "the content of this " + e.ResourceType + " should not be empty" - - if e.Hint != "" { - message += ", " + e.Hint - } - - return message -} - type UnknownCommandError struct { Command string } diff --git a/internal/executor/executors.go b/internal/executor/executors.go index 3b5ab40..bbcd689 100644 --- a/internal/executor/executors.go +++ b/internal/executor/executors.go @@ -128,7 +128,6 @@ type CreateExecutor struct { likeable bool replyable bool boostable bool - fromFile string inReplyTo string language string listRepliesPolicy string @@ -173,7 +172,6 @@ func NewCreateExecutor( 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.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") diff --git a/internal/executor/flags.go b/internal/executor/flags.go index 992ccb5..efd07a0 100644 --- a/internal/executor/flags.go +++ b/internal/executor/flags.go @@ -4,7 +4,6 @@ const ( flagAttachmentID = "attachment-id" flagContent = "content" flagFrom = "from" - flagFromFile = "from-file" flagInstance = "instance" flagListID = "list-id" flagListTitle = "list-title" diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index 2ab3749..a99d290 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -60,10 +60,6 @@ "type": "string", "description": "The resource type to action the target resource from (e.g. status)" }, - "from-file": { - "type": "string", - "description": "The file path where to read the contents from" - }, "full": { "type": "bool", "description": "Set to true to print the build information in full" @@ -257,7 +253,6 @@ { "flag": "enable-likes", "fieldName": "likeable", "default": "true" }, { "flag": "enable-replies", "fieldName": "replyable", "default": "true" }, { "flag": "enable-reposts", "fieldName": "boostable", "default": "true" }, - { "flag": "from-file", "default": "" }, { "flag": "in-reply-to", "default": "" }, { "flag": "language", "default": "" }, { "flag": "list-replies-policy", "default": "list" },