diff --git a/cmd/enbas/add.go b/cmd/enbas/add.go index 23c155c..93633f9 100644 --- a/cmd/enbas/add.go +++ b/cmd/enbas/add.go @@ -1,6 +1,7 @@ package main import ( + "errors" "flag" "fmt" @@ -14,6 +15,7 @@ type addCommand struct { toResourceType string listID string accountNames accountNames + content string } func newAddCommand(name, summary string) *addCommand { @@ -28,6 +30,7 @@ func newAddCommand(name, summary string) *addCommand { command.StringVar(&command.toResourceType, addToFlag, "", "specify the target resource type to add to (e.g. list, account, etc)") command.StringVar(&command.listID, listIDFlag, "", "the ID of the list to add to") command.Var(&command.accountNames, accountNameFlag, "the name of the account to add to the resource") + command.StringVar(&command.content, contentFlag, "", "the content of the note") command.Usage = commandUsageFunc(name, summary, command.FlagSet) @@ -40,7 +43,8 @@ func (c *addCommand) Execute() error { } funcMap := map[string]func(*client.Client) error{ - listResource: c.addToList, + listResource: c.addToList, + accountResource: c.addToAccount, } doFunc, ok := funcMap[c.toResourceType] @@ -97,3 +101,39 @@ func (c *addCommand) addAccountsToList(gtsClient *client.Client) error { return nil } + +func (c *addCommand) addToAccount(gtsClient *client.Client) error { + funcMap := map[string]func(*client.Client) error{ + noteResource: c.addNoteToAccount, + } + + doFunc, ok := funcMap[c.resourceType] + if !ok { + return unsupportedResourceTypeError{resourceType: c.resourceType} + } + + return doFunc(gtsClient) +} + +func (c *addCommand) addNoteToAccount(gtsClient *client.Client) error { + if len(c.accountNames) != 1 { + return fmt.Errorf("unexpected number of accounts specified; want 1, got %d", len(c.accountNames)) + } + + accountID, err := getAccountID(gtsClient, false, c.accountNames[0]) + if err != nil { + return fmt.Errorf("received an error while getting the account ID; %w", err) + } + + if c.content == "" { + return errors.New("the note content should not be empty") + } + + if err := gtsClient.SetPrivateNote(accountID, c.content); err != nil { + return fmt.Errorf("unable to add the private note to the account; %w", err) + } + + fmt.Println("Successfully added the private note to the account.") + + return nil +} diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index b036204..898da31 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -9,33 +9,35 @@ import ( const ( accountNameFlag = "account-name" addToFlag = "to" + contentFlag = "content" instanceFlag = "instance" + limitFlag = "limit" listIDFlag = "list-id" listTitleFlag = "list-title" listRepliesPolicyFlag = "list-replies-policy" myAccountFlag = "my-account" + notifyFlag = "notify" removeFromFlag = "from" resourceTypeFlag = "type" + showAccountRelationshipFlag = "show-account-relationship" + showUserPreferencesFlag = "show-preferences" + showRepostsFlag = "show-reposts" statusIDFlag = "status-id" tagFlag = "tag" timelineCategoryFlag = "timeline-category" - limitFlag = "limit" toAccountFlag = "to-account" - showRepostsFlag = "show-reposts" - notifyFlag = "notify" - showAccountRelationshipFlag = "show-account-relationship" - showUserPreferencesFlag = "show-preferences" ) const ( accountResource = "account" - instanceResource = "instance" - listResource = "list" - statusResource = "status" - timelineResource = "timeline" + blockedResource = "blocked" followersResource = "followers" followingResource = "following" - blockedResource = "blocked" + instanceResource = "instance" + listResource = "list" + noteResource = "note" + statusResource = "status" + timelineResource = "timeline" ) type Executor interface { diff --git a/internal/model/account.go b/internal/model/account.go index bd7bab0..6264e39 100644 --- a/internal/model/account.go +++ b/internal/model/account.go @@ -166,6 +166,7 @@ func (a AccountRelationship) String() string { ) if a.PrivateNote != "" { + output += "\n" output += fmt.Sprintf( privateNoteFormat, utilities.HeaderFormat("YOUR PRIVATE NOTE ABOUT THIS ACCOUNT:"),