Compare commits
No commits in common. "c04cd7e8a5edcfbca25c4a72af7f05ca6c55080b" and "5fb55ed2cfc4f01444022d4a586e3481cefbde26" have entirely different histories.
c04cd7e8a5
...
5fb55ed2cf
12 changed files with 256 additions and 293 deletions
13
cmd/enbas/errors.go
Normal file
13
cmd/enbas/errors.go
Normal file
|
@ -0,0 +1,13 @@
|
|||
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package main
|
||||
|
||||
type unknownCommandError struct {
|
||||
subcommand string
|
||||
}
|
||||
|
||||
func (e unknownCommandError) Error() string {
|
||||
return "unknown command '" + e.subcommand + "'"
|
||||
}
|
|
@ -13,6 +13,25 @@ import (
|
|||
"codeflow.dananglin.me.uk/apollo/enbas/internal/executor"
|
||||
)
|
||||
|
||||
const (
|
||||
commandLogin string = "login"
|
||||
commandVersion string = "version"
|
||||
commandShow string = "show"
|
||||
commandSwitch string = "switch"
|
||||
commandCreate string = "create"
|
||||
commandDelete string = "delete"
|
||||
commandEdit string = "edit"
|
||||
commandWhoami string = "whoami"
|
||||
commandAdd string = "add"
|
||||
commandRemove string = "remove"
|
||||
commandFollow string = "follow"
|
||||
commandUnfollow string = "unfollow"
|
||||
commandBlock string = "block"
|
||||
commandUnblock string = "unblock"
|
||||
commandAccept string = "accept"
|
||||
commandReject string = "reject"
|
||||
)
|
||||
|
||||
var (
|
||||
binaryVersion string
|
||||
buildTime string
|
||||
|
@ -28,23 +47,33 @@ func main() {
|
|||
}
|
||||
|
||||
func run() error {
|
||||
commandSummaries := map[string]string{
|
||||
commandLogin: "Login to an account on GoToSocial",
|
||||
commandVersion: "Print the application's version and build information",
|
||||
commandShow: "Print details about a specified resource",
|
||||
commandSwitch: "Perform a switch operation (e.g. switch logged in accounts)",
|
||||
commandCreate: "Create a specific resource",
|
||||
commandDelete: "Delete a specific resource",
|
||||
commandEdit: "Edit a specific resource",
|
||||
commandWhoami: "Print the account that you are currently logged in to",
|
||||
commandAdd: "Add a resource to another resource",
|
||||
commandRemove: "Remove a resource from another resource",
|
||||
commandFollow: "Follow a resource (e.g. an account)",
|
||||
commandUnfollow: "Unfollow a resource (e.g. an account)",
|
||||
commandBlock: "Block a resource (e.g. an account)",
|
||||
commandUnblock: "Unblock a resource (e.g. an account)",
|
||||
commandAccept: "Accept a request (e.g. a follow request)",
|
||||
commandReject: "Reject a request (e.g. a follow request)",
|
||||
}
|
||||
|
||||
topLevelFlags := executor.TopLevelFlags{
|
||||
ConfigDir: "",
|
||||
NoColor: nil,
|
||||
Pager: "",
|
||||
}
|
||||
|
||||
flag.StringVar(
|
||||
&topLevelFlags.ConfigDir,
|
||||
"config-dir",
|
||||
"",
|
||||
"Specify your config directory",
|
||||
)
|
||||
|
||||
flag.BoolFunc(
|
||||
"no-color",
|
||||
"Disable ANSI colour output when displaying text on screen",
|
||||
func(value string) error {
|
||||
flag.StringVar(&topLevelFlags.ConfigDir, "config-dir", "", "Specify your config directory")
|
||||
flag.BoolFunc("no-color", "Disable ANSI colour output when displaying text on screen", func(value string) error {
|
||||
boolVal, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse %q as a boolean: %w", value, err)
|
||||
|
@ -54,17 +83,10 @@ func run() error {
|
|||
*topLevelFlags.NoColor = boolVal
|
||||
|
||||
return nil
|
||||
},
|
||||
)
|
||||
})
|
||||
flag.StringVar(&topLevelFlags.Pager, "pager", "", "Specify your preferred pager to page through long outputs. This is disabled by default.")
|
||||
|
||||
flag.StringVar(
|
||||
&topLevelFlags.Pager,
|
||||
"pager",
|
||||
"",
|
||||
"Specify your preferred pager to page through long outputs. This is disabled by default.",
|
||||
)
|
||||
|
||||
flag.Usage = usageFunc(executor.CommandSummaryMap())
|
||||
flag.Usage = usageFunc(commandSummaries)
|
||||
|
||||
flag.Parse()
|
||||
|
||||
|
@ -87,100 +109,127 @@ func run() error {
|
|||
command := flag.Arg(0)
|
||||
args := flag.Args()[1:]
|
||||
|
||||
executorMap := map[string]executor.Executor{
|
||||
executor.CommandAccept: executor.NewAcceptOrRejectExecutor(
|
||||
var err error
|
||||
|
||||
switch command {
|
||||
case commandAccept:
|
||||
exe := executor.NewAcceptOrRejectExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandAccept,
|
||||
executor.CommandSummaryLookup(executor.CommandAccept),
|
||||
),
|
||||
executor.CommandAdd: executor.NewAddExecutor(
|
||||
commandAccept,
|
||||
commandSummaries[commandAccept],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandAdd:
|
||||
exe := executor.NewAddExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandAdd,
|
||||
executor.CommandSummaryLookup(executor.CommandAdd),
|
||||
),
|
||||
executor.CommandBlock: executor.NewBlockOrUnblockExecutor(
|
||||
commandAdd,
|
||||
commandSummaries[commandAdd],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandBlock:
|
||||
exe := executor.NewBlockExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandBlock,
|
||||
executor.CommandSummaryLookup(executor.CommandBlock),
|
||||
),
|
||||
executor.CommandCreate: executor.NewCreateExecutor(
|
||||
commandBlock,
|
||||
commandSummaries[commandBlock],
|
||||
false,
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandCreate:
|
||||
exe := executor.NewCreateExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandCreate,
|
||||
executor.CommandSummaryLookup(executor.CommandCreate),
|
||||
),
|
||||
executor.CommandDelete: executor.NewDeleteExecutor(
|
||||
commandCreate,
|
||||
commandSummaries[commandCreate],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandDelete:
|
||||
exe := executor.NewDeleteExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandDelete,
|
||||
executor.CommandSummaryLookup(executor.CommandDelete),
|
||||
),
|
||||
executor.CommandEdit: executor.NewEditExecutor(
|
||||
commandDelete,
|
||||
commandSummaries[commandDelete],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandEdit:
|
||||
exe := executor.NewEditExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandEdit,
|
||||
executor.CommandSummaryLookup(executor.CommandEdit),
|
||||
),
|
||||
executor.CommandFollow: executor.NewFollowOrUnfollowExecutor(
|
||||
commandEdit,
|
||||
commandSummaries[commandEdit],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandFollow:
|
||||
exe := executor.NewFollowExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandFollow,
|
||||
executor.CommandSummaryLookup(executor.CommandFollow),
|
||||
),
|
||||
executor.CommandLogin: executor.NewLoginExecutor(
|
||||
commandFollow,
|
||||
commandSummaries[commandFollow],
|
||||
false,
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandLogin:
|
||||
exe := executor.NewLoginExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandLogin,
|
||||
executor.CommandSummaryLookup(executor.CommandLogin),
|
||||
),
|
||||
executor.CommandReject: executor.NewAcceptOrRejectExecutor(
|
||||
commandLogin,
|
||||
commandSummaries[commandLogin],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandReject:
|
||||
exe := executor.NewAcceptOrRejectExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandReject,
|
||||
executor.CommandSummaryLookup(executor.CommandReject),
|
||||
),
|
||||
executor.CommandRemove: executor.NewRemoveExecutor(
|
||||
commandReject,
|
||||
commandSummaries[commandReject],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandRemove:
|
||||
exe := executor.NewRemoveExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandRemove,
|
||||
executor.CommandSummaryLookup(executor.CommandRemove),
|
||||
),
|
||||
executor.CommandSwitch: executor.NewSwitchExecutor(
|
||||
commandRemove,
|
||||
commandSummaries[commandRemove],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandSwitch:
|
||||
exe := executor.NewSwitchExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandSwitch,
|
||||
executor.CommandSummaryLookup(executor.CommandSwitch),
|
||||
),
|
||||
executor.CommandUnfollow: executor.NewFollowOrUnfollowExecutor(
|
||||
commandSwitch,
|
||||
commandSummaries[commandSwitch],
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandUnfollow:
|
||||
exe := executor.NewFollowExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandUnfollow,
|
||||
executor.CommandSummaryLookup(executor.CommandUnfollow),
|
||||
),
|
||||
executor.CommandUnblock: executor.NewBlockOrUnblockExecutor(
|
||||
commandUnfollow,
|
||||
commandSummaries[commandUnfollow],
|
||||
true,
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandUnblock:
|
||||
exe := executor.NewBlockExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandUnblock,
|
||||
executor.CommandSummaryLookup(executor.CommandUnblock),
|
||||
),
|
||||
executor.CommandShow: executor.NewShowExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandShow,
|
||||
executor.CommandSummaryLookup(executor.CommandShow),
|
||||
),
|
||||
executor.CommandVersion: executor.NewVersionExecutor(
|
||||
executor.CommandVersion,
|
||||
executor.CommandSummaryLookup(executor.CommandVersion),
|
||||
commandUnblock,
|
||||
commandSummaries[commandUnblock],
|
||||
true,
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandShow:
|
||||
exe := executor.NewShowExecutor(topLevelFlags, commandShow, commandSummaries[commandShow])
|
||||
err = executor.Execute(exe, args)
|
||||
case commandVersion:
|
||||
exe := executor.NewVersionExecutor(
|
||||
commandVersion,
|
||||
commandSummaries[commandVersion],
|
||||
binaryVersion,
|
||||
buildTime,
|
||||
goVersion,
|
||||
gitCommit,
|
||||
),
|
||||
executor.CommandWhoami: executor.NewWhoAmIExecutor(
|
||||
topLevelFlags,
|
||||
executor.CommandWhoami,
|
||||
executor.CommandSummaryLookup(executor.CommandWhoami),
|
||||
),
|
||||
}
|
||||
|
||||
exe, ok := executorMap[command]
|
||||
if !ok {
|
||||
)
|
||||
err = executor.Execute(exe, args)
|
||||
case commandWhoami:
|
||||
exe := executor.NewWhoAmIExecutor(topLevelFlags, commandWhoami, commandSummaries[commandWhoami])
|
||||
err = executor.Execute(exe, args)
|
||||
default:
|
||||
flag.Usage()
|
||||
|
||||
return executor.UnknownCommandError{Command: command}
|
||||
return unknownCommandError{command}
|
||||
}
|
||||
|
||||
if err := executor.Execute(exe, args); err != nil {
|
||||
if err != nil {
|
||||
return fmt.Errorf("(%s) %w", command, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ type AcceptOrRejectExecutor struct {
|
|||
topLevelFlags TopLevelFlags
|
||||
resourceType string
|
||||
accountName string
|
||||
command string
|
||||
action string
|
||||
}
|
||||
|
||||
func NewAcceptOrRejectExecutor(tlf TopLevelFlags, name, summary string) *AcceptOrRejectExecutor {
|
||||
|
@ -25,7 +25,7 @@ func NewAcceptOrRejectExecutor(tlf TopLevelFlags, name, summary string) *AcceptO
|
|||
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||
|
||||
topLevelFlags: tlf,
|
||||
command: name,
|
||||
action: name,
|
||||
}
|
||||
|
||||
acceptExe.StringVar(&acceptExe.resourceType, flagType, "", "Specify the type of resource to accept or reject")
|
||||
|
@ -60,10 +60,10 @@ func (a *AcceptOrRejectExecutor) acceptOrRejectFollowRequest(gtsClient *client.C
|
|||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
||||
switch a.command {
|
||||
case CommandAccept:
|
||||
switch a.action {
|
||||
case "accept":
|
||||
return a.acceptFollowRequest(gtsClient, accountID)
|
||||
case CommandReject:
|
||||
case "reject":
|
||||
return a.rejectFollowRequest(gtsClient, accountID)
|
||||
default:
|
||||
return nil
|
||||
|
|
|
@ -11,21 +11,21 @@ import (
|
|||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||
)
|
||||
|
||||
type BlockOrUnblockExecutor struct {
|
||||
type BlockExecutor struct {
|
||||
*flag.FlagSet
|
||||
|
||||
topLevelFlags TopLevelFlags
|
||||
resourceType string
|
||||
accountName string
|
||||
command string
|
||||
unblock bool
|
||||
}
|
||||
|
||||
func NewBlockOrUnblockExecutor(tlf TopLevelFlags, name, summary string) *BlockOrUnblockExecutor {
|
||||
blockExe := BlockOrUnblockExecutor{
|
||||
func NewBlockExecutor(tlf TopLevelFlags, name, summary string, unblock bool) *BlockExecutor {
|
||||
blockExe := BlockExecutor{
|
||||
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||
|
||||
topLevelFlags: tlf,
|
||||
command: name,
|
||||
unblock: unblock,
|
||||
}
|
||||
|
||||
blockExe.StringVar(&blockExe.resourceType, flagType, "", "Specify the type of resource to block or unblock")
|
||||
|
@ -36,9 +36,9 @@ func NewBlockOrUnblockExecutor(tlf TopLevelFlags, name, summary string) *BlockOr
|
|||
return &blockExe
|
||||
}
|
||||
|
||||
func (b *BlockOrUnblockExecutor) Execute() error {
|
||||
func (b *BlockExecutor) Execute() error {
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
resourceAccount: b.blockOrUnblockAccount,
|
||||
resourceAccount: b.blockAccount,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[b.resourceType]
|
||||
|
@ -54,23 +54,16 @@ func (b *BlockOrUnblockExecutor) Execute() error {
|
|||
return doFunc(gtsClient)
|
||||
}
|
||||
|
||||
func (b *BlockOrUnblockExecutor) blockOrUnblockAccount(gtsClient *client.Client) error {
|
||||
func (b *BlockExecutor) blockAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, b.accountName, b.topLevelFlags.ConfigDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
||||
switch b.command {
|
||||
case CommandBlock:
|
||||
return b.blockAccount(gtsClient, accountID)
|
||||
case CommandUnblock:
|
||||
if b.unblock {
|
||||
return b.unblockAccount(gtsClient, accountID)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func (b *BlockOrUnblockExecutor) blockAccount(gtsClient *client.Client, accountID string) error {
|
||||
if err := gtsClient.BlockAccount(accountID); err != nil {
|
||||
return fmt.Errorf("unable to block the account: %w", err)
|
||||
}
|
||||
|
@ -80,7 +73,7 @@ func (b *BlockOrUnblockExecutor) blockAccount(gtsClient *client.Client, accountI
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *BlockOrUnblockExecutor) unblockAccount(gtsClient *client.Client, accountID string) error {
|
||||
func (b *BlockExecutor) unblockAccount(gtsClient *client.Client, accountID string) error {
|
||||
if err := gtsClient.UnblockAccount(accountID); err != nil {
|
||||
return fmt.Errorf("unable to unblock the account: %w", err)
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package executor
|
||||
|
||||
const (
|
||||
CommandAccept string = "accept"
|
||||
CommandAdd string = "add"
|
||||
CommandBlock string = "block"
|
||||
CommandCreate string = "create"
|
||||
CommandDelete string = "delete"
|
||||
CommandEdit string = "edit"
|
||||
CommandFollow string = "follow"
|
||||
CommandLogin string = "login"
|
||||
CommandReject string = "reject"
|
||||
CommandRemove string = "remove"
|
||||
CommandShow string = "show"
|
||||
CommandSwitch string = "switch"
|
||||
CommandUnblock string = "unblock"
|
||||
CommandUnfollow string = "unfollow"
|
||||
CommandVersion string = "version"
|
||||
CommandWhoami string = "whoami"
|
||||
|
||||
commandAcceptSummary string = "Accept a request (e.g. a follow request)"
|
||||
commandAddSummary string = "Add a resource to another resource"
|
||||
commandBlockSummary string = "Block a resource (e.g. an account)"
|
||||
commandCreateSummary string = "Create a specific resource"
|
||||
commandDeleteSummary string = "Delete a specific resource"
|
||||
commandEditSummary string = "Edit a specific resource"
|
||||
commandFollowSummary string = "Follow a resource (e.g. an account)"
|
||||
commandLoginSummary string = "Login to an account on GoToSocial"
|
||||
commandRejectSummary string = "Reject a request (e.g. a follow request)"
|
||||
commandRemoveSummary string = "Remove a resource from another resource"
|
||||
commandShowSummary string = "Print details about a specified resource"
|
||||
commandSwitchSummary string = "Perform a switch operation (e.g. switch logged in accounts)"
|
||||
commandUnblockSummary string = "Unblock a resource (e.g. an account)"
|
||||
commandUnfollowSummary string = "Unfollow a resource (e.g. an account)"
|
||||
commandVersionSummary string = "Print the application's version and build information"
|
||||
commandWhoamiSummary string = "Print the account that you are currently logged in to"
|
||||
)
|
||||
|
||||
func CommandSummaryMap() map[string]string {
|
||||
return map[string]string{
|
||||
CommandAccept: commandAcceptSummary,
|
||||
CommandAdd: commandAddSummary,
|
||||
CommandBlock: commandBlockSummary,
|
||||
CommandCreate: commandCreateSummary,
|
||||
CommandDelete: commandDeleteSummary,
|
||||
CommandEdit: commandEditSummary,
|
||||
CommandFollow: commandFollowSummary,
|
||||
CommandLogin: commandLoginSummary,
|
||||
CommandReject: commandRejectSummary,
|
||||
CommandRemove: commandRemoveSummary,
|
||||
CommandShow: commandShowSummary,
|
||||
CommandSwitch: commandSwitchSummary,
|
||||
CommandUnblock: commandUnblockSummary,
|
||||
CommandUnfollow: commandUnfollowSummary,
|
||||
CommandVersion: commandVersionSummary,
|
||||
CommandWhoami: commandWhoamiSummary,
|
||||
}
|
||||
}
|
||||
|
||||
func CommandSummaryLookup(command string) string {
|
||||
commandMap := CommandSummaryMap()
|
||||
|
||||
summary, ok := commandMap[command]
|
||||
if !ok {
|
||||
return "This command does not have a summary"
|
||||
}
|
||||
|
||||
return summary
|
||||
}
|
54
internal/executor/const.go
Normal file
54
internal/executor/const.go
Normal file
|
@ -0,0 +1,54 @@
|
|||
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package executor
|
||||
|
||||
const (
|
||||
flagAccountName = "account-name"
|
||||
flagBrowser = "browser"
|
||||
flagContentType = "content-type"
|
||||
flagContent = "content"
|
||||
flagEnableFederation = "enable-federation"
|
||||
flagEnableLikes = "enable-likes"
|
||||
flagEnableReplies = "enable-replies"
|
||||
flagEnableReposts = "enable-reposts"
|
||||
flagFrom = "from"
|
||||
flagFromFile = "from-file"
|
||||
flagInstance = "instance"
|
||||
flagLanguage = "language"
|
||||
flagLimit = "limit"
|
||||
flagListID = "list-id"
|
||||
flagListTitle = "list-title"
|
||||
flagListRepliesPolicy = "list-replies-policy"
|
||||
flagMyAccount = "my-account"
|
||||
flagNotify = "notify"
|
||||
flagSensitive = "sensitive"
|
||||
flagSkipRelationship = "skip-relationship"
|
||||
flagShowPreferences = "show-preferences"
|
||||
flagShowReposts = "show-reposts"
|
||||
flagSpoilerText = "spoiler-text"
|
||||
flagStatusID = "status-id"
|
||||
flagTag = "tag"
|
||||
flagTimelineCategory = "timeline-category"
|
||||
flagTo = "to"
|
||||
flagType = "type"
|
||||
flagVisibility = "visibility"
|
||||
|
||||
resourceAccount = "account"
|
||||
resourceBlocked = "blocked"
|
||||
resourceBookmarks = "bookmarks"
|
||||
resourceBoost = "boost"
|
||||
resourceFollowers = "followers"
|
||||
resourceFollowing = "following"
|
||||
resourceFollowRequest = "follow-request"
|
||||
resourceInstance = "instance"
|
||||
resourceLike = "like"
|
||||
resourceLiked = "liked"
|
||||
resourceList = "list"
|
||||
resourceNote = "note"
|
||||
resourceStatus = "status"
|
||||
resourceStar = "star"
|
||||
resourceStarred = "starred"
|
||||
resourceTimeline = "timeline"
|
||||
)
|
|
@ -58,11 +58,3 @@ func (e EmptyContentError) Error() string {
|
|||
|
||||
return message
|
||||
}
|
||||
|
||||
type UnknownCommandError struct {
|
||||
Command string
|
||||
}
|
||||
|
||||
func (e UnknownCommandError) Error() string {
|
||||
return "unknown command '" + e.Command + "'"
|
||||
}
|
||||
|
|
|
@ -6,39 +6,6 @@ package executor
|
|||
|
||||
import "strings"
|
||||
|
||||
const (
|
||||
flagAccountName = "account-name"
|
||||
flagBrowser = "browser"
|
||||
flagContentType = "content-type"
|
||||
flagContent = "content"
|
||||
flagEnableFederation = "enable-federation"
|
||||
flagEnableLikes = "enable-likes"
|
||||
flagEnableReplies = "enable-replies"
|
||||
flagEnableReposts = "enable-reposts"
|
||||
flagFrom = "from"
|
||||
flagFromFile = "from-file"
|
||||
flagFull = "full"
|
||||
flagInstance = "instance"
|
||||
flagLanguage = "language"
|
||||
flagLimit = "limit"
|
||||
flagListID = "list-id"
|
||||
flagListTitle = "list-title"
|
||||
flagListRepliesPolicy = "list-replies-policy"
|
||||
flagMyAccount = "my-account"
|
||||
flagNotify = "notify"
|
||||
flagSensitive = "sensitive"
|
||||
flagSkipRelationship = "skip-relationship"
|
||||
flagShowPreferences = "show-preferences"
|
||||
flagShowReposts = "show-reposts"
|
||||
flagSpoilerText = "spoiler-text"
|
||||
flagStatusID = "status-id"
|
||||
flagTag = "tag"
|
||||
flagTimelineCategory = "timeline-category"
|
||||
flagTo = "to"
|
||||
flagType = "type"
|
||||
flagVisibility = "visibility"
|
||||
)
|
||||
|
||||
type AccountNames []string
|
||||
|
||||
func (a *AccountNames) String() string {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||
)
|
||||
|
||||
type FollowOrUnfollowExecutor struct {
|
||||
type FollowExecutor struct {
|
||||
*flag.FlagSet
|
||||
|
||||
topLevelFlags TopLevelFlags
|
||||
|
@ -19,15 +19,14 @@ type FollowOrUnfollowExecutor struct {
|
|||
accountName string
|
||||
showReposts bool
|
||||
notify bool
|
||||
action string
|
||||
unfollow bool
|
||||
}
|
||||
|
||||
func NewFollowOrUnfollowExecutor(tlf TopLevelFlags, name, summary string) *FollowOrUnfollowExecutor {
|
||||
command := FollowOrUnfollowExecutor{
|
||||
func NewFollowExecutor(tlf TopLevelFlags, name, summary string, unfollow bool) *FollowExecutor {
|
||||
command := FollowExecutor{
|
||||
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||
|
||||
unfollow: unfollow,
|
||||
topLevelFlags: tlf,
|
||||
action: name,
|
||||
}
|
||||
|
||||
command.StringVar(&command.resourceType, flagType, "", "Specify the type of resource to follow")
|
||||
|
@ -40,17 +39,17 @@ func NewFollowOrUnfollowExecutor(tlf TopLevelFlags, name, summary string) *Follo
|
|||
return &command
|
||||
}
|
||||
|
||||
func (f *FollowOrUnfollowExecutor) Execute() error {
|
||||
func (c *FollowExecutor) Execute() error {
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
resourceAccount: f.followOrUnfollowAccount,
|
||||
resourceAccount: c.followAccount,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[f.resourceType]
|
||||
doFunc, ok := funcMap[c.resourceType]
|
||||
if !ok {
|
||||
return UnsupportedTypeError{resourceType: f.resourceType}
|
||||
return UnsupportedTypeError{resourceType: c.resourceType}
|
||||
}
|
||||
|
||||
gtsClient, err := client.NewClientFromConfig(f.topLevelFlags.ConfigDir)
|
||||
gtsClient, err := client.NewClientFromConfig(c.topLevelFlags.ConfigDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create the GoToSocial client: %w", err)
|
||||
}
|
||||
|
@ -58,27 +57,20 @@ func (f *FollowOrUnfollowExecutor) Execute() error {
|
|||
return doFunc(gtsClient)
|
||||
}
|
||||
|
||||
func (f *FollowOrUnfollowExecutor) followOrUnfollowAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, f.accountName, f.topLevelFlags.ConfigDir)
|
||||
func (c *FollowExecutor) followAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, false, c.accountName, c.topLevelFlags.ConfigDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
}
|
||||
|
||||
switch f.action {
|
||||
case CommandFollow:
|
||||
return f.followAccount(gtsClient, accountID)
|
||||
case CommandUnfollow:
|
||||
return f.unfollowAccount(gtsClient, accountID)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
if c.unfollow {
|
||||
return c.unfollowAccount(gtsClient, accountID)
|
||||
}
|
||||
|
||||
func (f *FollowOrUnfollowExecutor) followAccount(gtsClient *client.Client, accountID string) error {
|
||||
form := client.FollowAccountForm{
|
||||
AccountID: accountID,
|
||||
ShowReposts: f.showReposts,
|
||||
Notify: f.notify,
|
||||
ShowReposts: c.showReposts,
|
||||
Notify: c.notify,
|
||||
}
|
||||
|
||||
if err := gtsClient.FollowAccount(form); err != nil {
|
||||
|
@ -90,7 +82,7 @@ func (f *FollowOrUnfollowExecutor) followAccount(gtsClient *client.Client, accou
|
|||
return nil
|
||||
}
|
||||
|
||||
func (f *FollowOrUnfollowExecutor) unfollowAccount(gtsClient *client.Client, accountID string) error {
|
||||
func (c *FollowExecutor) unfollowAccount(gtsClient *client.Client, accountID string) error {
|
||||
if err := gtsClient.UnfollowAccount(accountID); err != nil {
|
||||
return fmt.Errorf("unable to unfollow the account: %w", err)
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Dan Anglin <d.n.i.anglin@gmail.com>
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
package executor
|
||||
|
||||
const(
|
||||
resourceAccount = "account"
|
||||
resourceBlocked = "blocked"
|
||||
resourceBookmarks = "bookmarks"
|
||||
resourceBoost = "boost"
|
||||
resourceFollowers = "followers"
|
||||
resourceFollowing = "following"
|
||||
resourceFollowRequest = "follow-request"
|
||||
resourceInstance = "instance"
|
||||
resourceLike = "like"
|
||||
resourceLiked = "liked"
|
||||
resourceList = "list"
|
||||
resourceNote = "note"
|
||||
resourceStatus = "status"
|
||||
resourceStar = "star"
|
||||
resourceStarred = "starred"
|
||||
resourceTimeline = "timeline"
|
||||
)
|
|
@ -30,7 +30,7 @@ func NewVersionExecutor(name, summary, binaryVersion, buildTime, goVersion, gitC
|
|||
showFullVersion: false,
|
||||
}
|
||||
|
||||
command.BoolVar(&command.showFullVersion, flagFull, false, "prints the full build information")
|
||||
command.BoolVar(&command.showFullVersion, "Full", false, "prints the full build information")
|
||||
|
||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||
|
||||
|
|
|
@ -199,15 +199,15 @@ func (a AccountList) Display(noColor bool) string {
|
|||
|
||||
switch a.Type {
|
||||
case AccountListFollowers:
|
||||
output += utilities.HeaderFormat(noColor, "Followed by:")
|
||||
output += utilities.HeaderFormat(noColor, "FOLLOWED BY:")
|
||||
case AccountListFollowing:
|
||||
output += utilities.HeaderFormat(noColor, "Following:")
|
||||
output += utilities.HeaderFormat(noColor, "FOLLOWING:")
|
||||
case AccountListBlockedAccount:
|
||||
output += utilities.HeaderFormat(noColor, "Blocked accounts:")
|
||||
output += utilities.HeaderFormat(noColor, "BLOCKED ACCOUNTS:")
|
||||
case AccountListFollowRequests:
|
||||
output += utilities.HeaderFormat(noColor, "Accounts that have requested to follow you:")
|
||||
output += utilities.HeaderFormat(noColor, "ACCOUNTS THAT HAVE REQUESTED TO FOLLOW YOU:")
|
||||
default:
|
||||
output += utilities.HeaderFormat(noColor, "Accounts:")
|
||||
output += utilities.HeaderFormat(noColor, "ACCOUNTS:")
|
||||
}
|
||||
|
||||
if a.Type == AccountListBlockedAccount {
|
||||
|
|
Loading…
Reference in a new issue