fix(BREAKING): remove the from-file flag
All checks were successful
REUSE Compliance Check / check (push) Successful in 8s

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
This commit is contained in:
Dan Anglin 2024-08-16 19:57:44 +01:00
parent c0f1f7d03a
commit 39d9ef1a38
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
7 changed files with 13 additions and 49 deletions

View file

@ -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.<br>Here this should be `status`. | |
| `attachment-id` | string | false | The ID of the media attachment to attach to the status.<br>Use this flag multiple times to attach multiple media. |
| `content` | string | false | The content of the status.<br>This flag takes precedence over `from-file`.| |
| `content` | string | false | The content of the status.<br>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.<br>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.<br>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.<br>Use this flag multiple times to upload multiple media files. | |

View file

@ -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 {

View file

@ -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)

View file

@ -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
}

View file

@ -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")

View file

@ -4,7 +4,6 @@ const (
flagAttachmentID = "attachment-id"
flagContent = "content"
flagFrom = "from"
flagFromFile = "from-file"
flagInstance = "instance"
flagListID = "list-id"
flagListTitle = "list-title"

View file

@ -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" },