Compare commits
2 commits
236f10e006
...
3e9290897c
Author | SHA1 | Date | |
---|---|---|---|
3e9290897c | |||
3d17c30d0f |
18 changed files with 171 additions and 201 deletions
|
@ -47,7 +47,6 @@ You can install Enbas with Mage using the following commands:
|
||||||
[source,console]
|
[source,console]
|
||||||
----
|
----
|
||||||
git clone https://github.com/dananglin/enbas.git
|
git clone https://github.com/dananglin/enbas.git
|
||||||
cd enbas/internal/build/
|
|
||||||
mage install
|
mage install
|
||||||
----
|
----
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,11 @@ func newAddCommand(tlf topLevelFlags, name, summary string) *addCommand {
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the resource type to add (e.g. account, note)")
|
command.StringVar(&command.resourceType, flagType, "", "specify the resource type to add (e.g. account, note)")
|
||||||
command.StringVar(&command.toResourceType, addToFlag, "", "specify the target resource type to add to (e.g. list, account, etc)")
|
command.StringVar(&command.toResourceType, flagTo, "", "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.StringVar(&command.listID, flagListID, "", "the ID of the list to add to")
|
||||||
command.Var(&command.accountNames, accountNameFlag, "the name of the account to add to the resource")
|
command.Var(&command.accountNames, flagAccountName, "the name of the account to add to the resource")
|
||||||
command.StringVar(&command.content, contentFlag, "", "the content of the note")
|
command.StringVar(&command.content, flagContent, "", "the content of the note")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ func newAddCommand(tlf topLevelFlags, name, summary string) *addCommand {
|
||||||
|
|
||||||
func (c *addCommand) Execute() error {
|
func (c *addCommand) Execute() error {
|
||||||
if c.toResourceType == "" {
|
if c.toResourceType == "" {
|
||||||
return flagNotSetError{flagText: addToFlag}
|
return flagNotSetError{flagText: flagTo}
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.addToList,
|
resourceList: c.addToList,
|
||||||
accountResource: c.addToAccount,
|
resourceAccount: c.addToAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.toResourceType]
|
doFunc, ok := funcMap[c.toResourceType]
|
||||||
|
@ -64,7 +64,7 @@ func (c *addCommand) Execute() error {
|
||||||
|
|
||||||
func (c *addCommand) addToList(gtsClient *client.Client) error {
|
func (c *addCommand) addToList(gtsClient *client.Client) error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
accountResource: c.addAccountsToList,
|
resourceAccount: c.addAccountsToList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -80,7 +80,7 @@ func (c *addCommand) addToList(gtsClient *client.Client) error {
|
||||||
|
|
||||||
func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.accountNames) == 0 {
|
if len(c.accountNames) == 0 {
|
||||||
|
@ -109,7 +109,7 @@ func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
||||||
|
|
||||||
func (c *addCommand) addToAccount(gtsClient *client.Client) error {
|
func (c *addCommand) addToAccount(gtsClient *client.Client) error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
noteResource: c.addNoteToAccount,
|
resourceNote: c.addNoteToAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
|
|
@ -24,8 +24,8 @@ func newBlockCommand(tlf topLevelFlags, name, summary string, unblock bool) *blo
|
||||||
unblock: unblock,
|
unblock: unblock,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to block or unblock")
|
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to block or unblock")
|
||||||
command.StringVar(&command.accountName, accountNameFlag, "", "specify the account name in full (username@domain)")
|
command.StringVar(&command.accountName, flagAccountName, "", "specify the account name in full (username@domain)")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ func newBlockCommand(tlf topLevelFlags, name, summary string, unblock bool) *blo
|
||||||
|
|
||||||
func (c *blockCommand) Execute() error {
|
func (c *blockCommand) Execute() error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
accountResource: c.blockAccount,
|
resourceAccount: c.blockAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
|
|
@ -24,9 +24,9 @@ func newCreateCommand(tlf topLevelFlags, name, summary string) *createCommand {
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to create")
|
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to create")
|
||||||
command.StringVar(&command.listTitle, listTitleFlag, "", "specify the title of the list")
|
command.StringVar(&command.listTitle, flagListTitle, "", "specify the title of the list")
|
||||||
command.StringVar(&command.listRepliesPolicy, listRepliesPolicyFlag, "list", "specify the policy of the replies for this list (valid values are followed, list and none)")
|
command.StringVar(&command.listRepliesPolicy, flagListRepliesPolicy, "list", "specify the policy of the replies for this list (valid values are followed, list and none)")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func newCreateCommand(tlf topLevelFlags, name, summary string) *createCommand {
|
||||||
|
|
||||||
func (c *createCommand) Execute() error {
|
func (c *createCommand) Execute() error {
|
||||||
if c.resourceType == "" {
|
if c.resourceType == "" {
|
||||||
return flagNotSetError{flagText: resourceTypeFlag}
|
return flagNotSetError{flagText: flagType}
|
||||||
}
|
}
|
||||||
|
|
||||||
gtsClient, err := client.NewClientFromConfig(c.topLevelFlags.configDir)
|
gtsClient, err := client.NewClientFromConfig(c.topLevelFlags.configDir)
|
||||||
|
@ -44,7 +44,7 @@ func (c *createCommand) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.createList,
|
resourceList: c.createList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -57,7 +57,7 @@ func (c *createCommand) Execute() error {
|
||||||
|
|
||||||
func (c *createCommand) createList(gtsClient *client.Client) error {
|
func (c *createCommand) createList(gtsClient *client.Client) error {
|
||||||
if c.listTitle == "" {
|
if c.listTitle == "" {
|
||||||
return flagNotSetError{flagText: listTitleFlag}
|
return flagNotSetError{flagText: flagListTitle}
|
||||||
}
|
}
|
||||||
|
|
||||||
repliesPolicy, err := model.ParseListRepliesPolicy(c.listRepliesPolicy)
|
repliesPolicy, err := model.ParseListRepliesPolicy(c.listRepliesPolicy)
|
||||||
|
|
|
@ -22,8 +22,8 @@ func newDeleteCommand(tlf topLevelFlags, name, summary string) *deleteCommand {
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to delete")
|
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to delete")
|
||||||
command.StringVar(&command.listID, listIDFlag, "", "specify the ID of the list to delete")
|
command.StringVar(&command.listID, flagListID, "", "specify the ID of the list to delete")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -32,11 +32,11 @@ func newDeleteCommand(tlf topLevelFlags, name, summary string) *deleteCommand {
|
||||||
|
|
||||||
func (c *deleteCommand) Execute() error {
|
func (c *deleteCommand) Execute() error {
|
||||||
if c.resourceType == "" {
|
if c.resourceType == "" {
|
||||||
return flagNotSetError{flagText: resourceTypeFlag}
|
return flagNotSetError{flagText: flagType}
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.deleteList,
|
resourceList: c.deleteList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -54,7 +54,7 @@ func (c *deleteCommand) Execute() error {
|
||||||
|
|
||||||
func (c *deleteCommand) deleteList(gtsClient *client.Client) error {
|
func (c *deleteCommand) deleteList(gtsClient *client.Client) error {
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gtsClient.DeleteList(c.listID); err != nil {
|
if err := gtsClient.DeleteList(c.listID); err != nil {
|
||||||
|
|
|
@ -25,10 +25,10 @@ func newFollowCommand(tlf topLevelFlags, name, summary string, unfollow bool) *f
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to follow")
|
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to follow")
|
||||||
command.StringVar(&command.accountName, accountNameFlag, "", "specify the account name in full (username@domain)")
|
command.StringVar(&command.accountName, flagAccountName, "", "specify the account name in full (username@domain)")
|
||||||
command.BoolVar(&command.showReposts, showRepostsFlag, true, "show reposts from the account you want to follow")
|
command.BoolVar(&command.showReposts, flagShowReposts, true, "show reposts from the account you want to follow")
|
||||||
command.BoolVar(&command.notify, notifyFlag, false, "get notifications when the account you want to follow posts a status")
|
command.BoolVar(&command.notify, flagNotify, false, "get notifications when the account you want to follow posts a status")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ func newFollowCommand(tlf topLevelFlags, name, summary string, unfollow bool) *f
|
||||||
|
|
||||||
func (c *followCommand) Execute() error {
|
func (c *followCommand) Execute() error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
accountResource: c.followAccount,
|
resourceAccount: c.followAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
|
|
@ -24,7 +24,7 @@ func newLoginCommand(tlf topLevelFlags, name, summary string) *loginCommand {
|
||||||
instance: "",
|
instance: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.instance, instanceFlag, "", "specify the instance that you want to login to.")
|
command.StringVar(&command.instance, flagInstance, "", "specify the instance that you want to login to.")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ func (c *loginCommand) Execute() error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
if c.instance == "" {
|
if c.instance == "" {
|
||||||
return flagNotSetError{flagText: instanceFlag}
|
return flagNotSetError{flagText: flagInstance}
|
||||||
}
|
}
|
||||||
|
|
||||||
instance := c.instance
|
instance := c.instance
|
||||||
|
|
|
@ -7,37 +7,36 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
accountNameFlag = "account-name"
|
flagAccountName = "account-name"
|
||||||
addToFlag = "to"
|
flagTo = "to"
|
||||||
contentFlag = "content"
|
flagContent = "content"
|
||||||
instanceFlag = "instance"
|
flagInstance = "instance"
|
||||||
limitFlag = "limit"
|
flagLimit = "limit"
|
||||||
listIDFlag = "list-id"
|
flagListID = "list-id"
|
||||||
listTitleFlag = "list-title"
|
flagListTitle = "list-title"
|
||||||
listRepliesPolicyFlag = "list-replies-policy"
|
flagListRepliesPolicy = "list-replies-policy"
|
||||||
myAccountFlag = "my-account"
|
flagMyAccount = "my-account"
|
||||||
notifyFlag = "notify"
|
flagNotify = "notify"
|
||||||
removeFromFlag = "from"
|
flagFrom = "from"
|
||||||
resourceTypeFlag = "type"
|
flagType = "type"
|
||||||
showAccountRelationshipFlag = "show-account-relationship"
|
flagShowRelationship = "show-relationship"
|
||||||
showUserPreferencesFlag = "show-preferences"
|
flagShowPreferences = "show-preferences"
|
||||||
showRepostsFlag = "show-reposts"
|
flagShowReposts = "show-reposts"
|
||||||
statusIDFlag = "status-id"
|
flagStatusID = "status-id"
|
||||||
tagFlag = "tag"
|
flagTag = "tag"
|
||||||
timelineCategoryFlag = "timeline-category"
|
flagTimelineCategory = "timeline-category"
|
||||||
toAccountFlag = "to-account"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
accountResource = "account"
|
resourceAccount = "account"
|
||||||
blockedResource = "blocked"
|
resourceBlocked = "blocked"
|
||||||
followersResource = "followers"
|
resourceFollowers = "followers"
|
||||||
followingResource = "following"
|
resourceFollowing = "following"
|
||||||
instanceResource = "instance"
|
resourceInstance = "instance"
|
||||||
listResource = "list"
|
resourceList = "list"
|
||||||
noteResource = "note"
|
resourceNote = "note"
|
||||||
statusResource = "status"
|
resourceStatus = "status"
|
||||||
timelineResource = "timeline"
|
resourceTimeline = "timeline"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Executor interface {
|
type Executor interface {
|
||||||
|
@ -55,44 +54,44 @@ func main() {
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
const (
|
const (
|
||||||
login string = "login"
|
commandLogin string = "login"
|
||||||
version string = "version"
|
commandVersion string = "version"
|
||||||
showResource string = "show"
|
commandShow string = "show"
|
||||||
switchAccount string = "switch"
|
commandSwitchAccount string = "switch-account"
|
||||||
createResource string = "create"
|
commandCreate string = "create"
|
||||||
deleteResource string = "delete"
|
commandDelete string = "delete"
|
||||||
updateResource string = "update"
|
commandUpdate string = "update"
|
||||||
whoami string = "whoami"
|
commandWhoami string = "whoami"
|
||||||
add string = "add"
|
commandAdd string = "add"
|
||||||
remove string = "remove"
|
commandRemove string = "remove"
|
||||||
follow string = "follow"
|
commandFollow string = "follow"
|
||||||
unfollow string = "unfollow"
|
commandUnfollow string = "unfollow"
|
||||||
block string = "block"
|
commandBlock string = "block"
|
||||||
unblock string = "unblock"
|
commandUnblock string = "unblock"
|
||||||
)
|
)
|
||||||
|
|
||||||
summaries := map[string]string{
|
commandSummaries := map[string]string{
|
||||||
login: "login to an account on GoToSocial",
|
commandLogin: "login to an account on GoToSocial",
|
||||||
version: "print the application's version and build information",
|
commandVersion: "print the application's version and build information",
|
||||||
showResource: "print details about a specified resource",
|
commandShow: "print details about a specified resource",
|
||||||
switchAccount: "switch to an account",
|
commandSwitchAccount: "switch to a different account",
|
||||||
createResource: "create a specific resource",
|
commandCreate: "create a specific resource",
|
||||||
deleteResource: "delete a specific resource",
|
commandDelete: "delete a specific resource",
|
||||||
updateResource: "update a specific resource",
|
commandUpdate: "update a specific resource",
|
||||||
whoami: "print the account that you are currently logged in to",
|
commandWhoami: "print the account that you are currently logged in to",
|
||||||
add: "add a resource to another resource",
|
commandAdd: "add a resource to another resource",
|
||||||
remove: "remove a resource from another resource",
|
commandRemove: "remove a resource from another resource",
|
||||||
follow: "follow a resource (e.g. an account)",
|
commandFollow: "follow a resource (e.g. an account)",
|
||||||
unfollow: "unfollow a resource (e.g. an account)",
|
commandUnfollow: "unfollow a resource (e.g. an account)",
|
||||||
block: "block a resource (e.g. an account)",
|
commandBlock: "block a resource (e.g. an account)",
|
||||||
unblock: "unblock a resource (e.g. an account)",
|
commandUnblock: "unblock a resource (e.g. an account)",
|
||||||
}
|
}
|
||||||
|
|
||||||
tlf := topLevelFlags{}
|
tlf := topLevelFlags{}
|
||||||
|
|
||||||
flag.StringVar(&tlf.configDir, "config-dir", "", "specify your config directory")
|
flag.StringVar(&tlf.configDir, "config-dir", "", "specify your config directory")
|
||||||
|
|
||||||
flag.Usage = enbasUsageFunc(summaries)
|
flag.Usage = enbasUsageFunc(commandSummaries)
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
@ -102,46 +101,50 @@ func run() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
subcommand := flag.Arg(0)
|
command := flag.Arg(0)
|
||||||
args := flag.Args()[1:]
|
args := flag.Args()[1:]
|
||||||
|
|
||||||
|
// TODO: will not be needed anymore
|
||||||
var executor Executor
|
var executor Executor
|
||||||
|
|
||||||
switch subcommand {
|
switch command {
|
||||||
case login:
|
case commandLogin:
|
||||||
executor = newLoginCommand(tlf, login, summaries[login])
|
executor = newLoginCommand(tlf, commandLogin, commandSummaries[commandLogin])
|
||||||
case version:
|
case commandVersion:
|
||||||
executor = newVersionCommand(version, summaries[version])
|
executor = newVersionCommand(commandVersion, commandSummaries[commandVersion])
|
||||||
case showResource:
|
case commandShow:
|
||||||
executor = newShowCommand(tlf, showResource, summaries[showResource])
|
executor = newShowCommand(tlf, commandShow, commandSummaries[commandShow])
|
||||||
case switchAccount:
|
case commandSwitchAccount:
|
||||||
executor = newSwitchCommand(tlf, switchAccount, summaries[switchAccount])
|
executor = newSwitchCommand(tlf, commandSwitchAccount, commandSummaries[commandSwitchAccount])
|
||||||
case createResource:
|
case commandCreate:
|
||||||
executor = newCreateCommand(tlf, createResource, summaries[createResource])
|
executor = newCreateCommand(tlf, commandCreate, commandSummaries[commandCreate])
|
||||||
case deleteResource:
|
case commandDelete:
|
||||||
executor = newDeleteCommand(tlf, deleteResource, summaries[deleteResource])
|
executor = newDeleteCommand(tlf, commandDelete, commandSummaries[commandDelete])
|
||||||
case updateResource:
|
case commandUpdate:
|
||||||
executor = newUpdateCommand(tlf, updateResource, summaries[updateResource])
|
executor = newUpdateCommand(tlf, commandUpdate, commandSummaries[commandUpdate])
|
||||||
case whoami:
|
case commandWhoami:
|
||||||
executor = newWhoAmICommand(tlf, whoami, summaries[whoami])
|
executor = newWhoAmICommand(tlf, commandWhoami, commandSummaries[commandWhoami])
|
||||||
case add:
|
case commandAdd:
|
||||||
executor = newAddCommand(tlf, add, summaries[add])
|
executor = newAddCommand(tlf, commandAdd, commandSummaries[commandAdd])
|
||||||
case remove:
|
case commandRemove:
|
||||||
executor = newRemoveCommand(tlf, remove, summaries[remove])
|
executor = newRemoveCommand(tlf, commandRemove, commandSummaries[commandRemove])
|
||||||
case follow:
|
case commandFollow:
|
||||||
executor = newFollowCommand(tlf, follow, summaries[follow], false)
|
executor = newFollowCommand(tlf, commandFollow, commandSummaries[commandFollow], false)
|
||||||
case unfollow:
|
case commandUnfollow:
|
||||||
executor = newFollowCommand(tlf, unfollow, summaries[unfollow], true)
|
executor = newFollowCommand(tlf, commandUnfollow, commandSummaries[commandUnfollow], true)
|
||||||
case block:
|
case commandBlock:
|
||||||
executor = newBlockCommand(tlf, block, summaries[block], false)
|
executor = newBlockCommand(tlf, commandBlock, commandSummaries[commandBlock], false)
|
||||||
case unblock:
|
case commandUnblock:
|
||||||
executor = newBlockCommand(tlf, unblock, summaries[unblock], true)
|
executor = newBlockCommand(tlf, commandUnblock, commandSummaries[commandUnblock], true)
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
|
|
||||||
return unknownSubcommandError{subcommand}
|
return unknownSubcommandError{command}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// To Do: create a function in executor package that will take in concrete type
|
||||||
|
// as interface and run the parse and execute command.
|
||||||
|
|
||||||
if err := executor.Parse(args); err != nil {
|
if err := executor.Parse(args); err != nil {
|
||||||
return fmt.Errorf("unable to parse the command line flags; %w", err)
|
return fmt.Errorf("unable to parse the command line flags; %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,10 +26,10 @@ func newRemoveCommand(tlf topLevelFlags, name, summary string) *removeCommand {
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the resource type to remove (e.g. account, note)")
|
command.StringVar(&command.resourceType, flagType, "", "specify the resource type to remove (e.g. account, note)")
|
||||||
command.StringVar(&command.fromResourceType, removeFromFlag, "", "specify the resource type to remove from (e.g. list, account, etc)")
|
command.StringVar(&command.fromResourceType, flagFrom, "", "specify the resource type to remove from (e.g. list, account, etc)")
|
||||||
command.StringVar(&command.listID, listIDFlag, "", "the ID of the list to remove from")
|
command.StringVar(&command.listID, flagListID, "", "the ID of the list to remove from")
|
||||||
command.Var(&command.accountNames, accountNameFlag, "the name of the account to remove from the resource")
|
command.Var(&command.accountNames, flagAccountName, "the name of the account to remove from the resource")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -38,12 +38,12 @@ func newRemoveCommand(tlf topLevelFlags, name, summary string) *removeCommand {
|
||||||
|
|
||||||
func (c *removeCommand) Execute() error {
|
func (c *removeCommand) Execute() error {
|
||||||
if c.fromResourceType == "" {
|
if c.fromResourceType == "" {
|
||||||
return flagNotSetError{flagText: removeFromFlag}
|
return flagNotSetError{flagText: flagFrom}
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.removeFromList,
|
resourceList: c.removeFromList,
|
||||||
accountResource: c.removeFromAccount,
|
resourceAccount: c.removeFromAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.fromResourceType]
|
doFunc, ok := funcMap[c.fromResourceType]
|
||||||
|
@ -61,7 +61,7 @@ func (c *removeCommand) Execute() error {
|
||||||
|
|
||||||
func (c *removeCommand) removeFromList(gtsClient *client.Client) error {
|
func (c *removeCommand) removeFromList(gtsClient *client.Client) error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
accountResource: c.removeAccountsFromList,
|
resourceAccount: c.removeAccountsFromList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -77,7 +77,7 @@ func (c *removeCommand) removeFromList(gtsClient *client.Client) error {
|
||||||
|
|
||||||
func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error {
|
func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error {
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.accountNames) == 0 {
|
if len(c.accountNames) == 0 {
|
||||||
|
@ -106,7 +106,7 @@ func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error {
|
||||||
|
|
||||||
func (c *removeCommand) removeFromAccount(gtsClient *client.Client) error {
|
func (c *removeCommand) removeFromAccount(gtsClient *client.Client) error {
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
noteResource: c.removeNoteFromAccount,
|
resourceNote: c.removeNoteFromAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
|
|
@ -30,16 +30,16 @@ func newShowCommand(tlf topLevelFlags, name, summary string) *showCommand {
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.BoolVar(&command.myAccount, myAccountFlag, false, "set to true to lookup your account")
|
command.BoolVar(&command.myAccount, flagMyAccount, false, "set to true to lookup your account")
|
||||||
command.BoolVar(&command.showAccountRelationship, showAccountRelationshipFlag, false, "show your relationship to the specified account")
|
command.BoolVar(&command.showAccountRelationship, flagShowRelationship, false, "show your relationship to the specified account")
|
||||||
command.BoolVar(&command.showUserPreferences, showUserPreferencesFlag, false, "show your preferences")
|
command.BoolVar(&command.showUserPreferences, flagShowPreferences, false, "show your preferences")
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to display")
|
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to display")
|
||||||
command.StringVar(&command.accountName, accountNameFlag, "", "specify the account name in full (username@domain)")
|
command.StringVar(&command.accountName, flagAccountName, "", "specify the account name in full (username@domain)")
|
||||||
command.StringVar(&command.statusID, statusIDFlag, "", "specify the ID of the status to display")
|
command.StringVar(&command.statusID, flagStatusID, "", "specify the ID of the status to display")
|
||||||
command.StringVar(&command.timelineCategory, timelineCategoryFlag, "home", "specify the type of timeline to display (valid values are home, public, list and tag)")
|
command.StringVar(&command.timelineCategory, flagTimelineCategory, "home", "specify the type of timeline to display (valid values are home, public, list and tag)")
|
||||||
command.StringVar(&command.listID, listIDFlag, "", "specify the ID of the list to display")
|
command.StringVar(&command.listID, flagListID, "", "specify the ID of the list to display")
|
||||||
command.StringVar(&command.tag, tagFlag, "", "specify the name of the tag to use")
|
command.StringVar(&command.tag, flagTag, "", "specify the name of the tag to use")
|
||||||
command.IntVar(&command.limit, limitFlag, 20, "specify the limit of items to display")
|
command.IntVar(&command.limit, flagLimit, 20, "specify the limit of items to display")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -48,18 +48,18 @@ func newShowCommand(tlf topLevelFlags, name, summary string) *showCommand {
|
||||||
|
|
||||||
func (c *showCommand) Execute() error {
|
func (c *showCommand) Execute() error {
|
||||||
if c.resourceType == "" {
|
if c.resourceType == "" {
|
||||||
return flagNotSetError{flagText: resourceTypeFlag}
|
return flagNotSetError{flagText: flagType}
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
instanceResource: c.showInstance,
|
resourceInstance: c.showInstance,
|
||||||
accountResource: c.showAccount,
|
resourceAccount: c.showAccount,
|
||||||
statusResource: c.showStatus,
|
resourceStatus: c.showStatus,
|
||||||
timelineResource: c.showTimeline,
|
resourceTimeline: c.showTimeline,
|
||||||
listResource: c.showList,
|
resourceList: c.showList,
|
||||||
followersResource: c.showFollowers,
|
resourceFollowers: c.showFollowers,
|
||||||
followingResource: c.showFollowing,
|
resourceFollowing: c.showFollowing,
|
||||||
blockedResource: c.showBlocked,
|
resourceBlocked: c.showBlocked,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -99,7 +99,7 @@ func (c *showCommand) showAccount(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if c.accountName == "" {
|
if c.accountName == "" {
|
||||||
return flagNotSetError{flagText: accountNameFlag}
|
return flagNotSetError{flagText: flagAccountName}
|
||||||
}
|
}
|
||||||
|
|
||||||
account, err = getAccount(gtsClient, c.accountName)
|
account, err = getAccount(gtsClient, c.accountName)
|
||||||
|
@ -133,7 +133,7 @@ func (c *showCommand) showAccount(gtsClient *client.Client) error {
|
||||||
|
|
||||||
func (c *showCommand) showStatus(gtsClient *client.Client) error {
|
func (c *showCommand) showStatus(gtsClient *client.Client) error {
|
||||||
if c.statusID == "" {
|
if c.statusID == "" {
|
||||||
return flagNotSetError{flagText: statusIDFlag}
|
return flagNotSetError{flagText: flagStatusID}
|
||||||
}
|
}
|
||||||
|
|
||||||
status, err := gtsClient.GetStatus(c.statusID)
|
status, err := gtsClient.GetStatus(c.statusID)
|
||||||
|
@ -159,13 +159,13 @@ func (c *showCommand) showTimeline(gtsClient *client.Client) error {
|
||||||
timeline, err = gtsClient.GetPublicTimeline(c.limit)
|
timeline, err = gtsClient.GetPublicTimeline(c.limit)
|
||||||
case "list":
|
case "list":
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeline, err = gtsClient.GetListTimeline(c.listID, c.limit)
|
timeline, err = gtsClient.GetListTimeline(c.listID, c.limit)
|
||||||
case "tag":
|
case "tag":
|
||||||
if c.tag == "" {
|
if c.tag == "" {
|
||||||
return flagNotSetError{flagText: tagFlag}
|
return flagNotSetError{flagText: flagTag}
|
||||||
}
|
}
|
||||||
|
|
||||||
timeline, err = gtsClient.GetTagTimeline(c.tag, c.limit)
|
timeline, err = gtsClient.GetTagTimeline(c.tag, c.limit)
|
||||||
|
|
|
@ -20,7 +20,7 @@ func newSwitchCommand(tlf topLevelFlags, name, summary string) *switchCommand {
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.toAccount, toAccountFlag, "", "the account to switch to")
|
command.StringVar(&command.toAccount, flagTo, "", "the account to switch to")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ func newSwitchCommand(tlf topLevelFlags, name, summary string) *switchCommand {
|
||||||
|
|
||||||
func (c *switchCommand) Execute() error {
|
func (c *switchCommand) Execute() error {
|
||||||
if c.toAccount == "" {
|
if c.toAccount == "" {
|
||||||
return flagNotSetError{flagText: toAccountFlag}
|
return flagNotSetError{flagText: flagTo}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := config.UpdateCurrentAccount(c.toAccount, c.topLevelFlags.configDir); err != nil {
|
if err := config.UpdateCurrentAccount(c.toAccount, c.topLevelFlags.configDir); err != nil {
|
||||||
|
|
|
@ -24,10 +24,10 @@ func newUpdateCommand(tlf topLevelFlags, name, summary string) *updateCommand {
|
||||||
topLevelFlags: tlf,
|
topLevelFlags: tlf,
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to update")
|
command.StringVar(&command.resourceType, flagType, "", "specify the type of resource to update")
|
||||||
command.StringVar(&command.listID, listIDFlag, "", "specify the ID of the list to update")
|
command.StringVar(&command.listID, flagListID, "", "specify the ID of the list to update")
|
||||||
command.StringVar(&command.listTitle, listTitleFlag, "", "specify the title of the list")
|
command.StringVar(&command.listTitle, flagListTitle, "", "specify the title of the list")
|
||||||
command.StringVar(&command.listRepliesPolicy, listRepliesPolicyFlag, "", "specify the policy of the replies for this list (valid values are followed, list and none)")
|
command.StringVar(&command.listRepliesPolicy, flagListRepliesPolicy, "", "specify the policy of the replies for this list (valid values are followed, list and none)")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -36,11 +36,11 @@ func newUpdateCommand(tlf topLevelFlags, name, summary string) *updateCommand {
|
||||||
|
|
||||||
func (c *updateCommand) Execute() error {
|
func (c *updateCommand) Execute() error {
|
||||||
if c.resourceType == "" {
|
if c.resourceType == "" {
|
||||||
return flagNotSetError{flagText: resourceTypeFlag}
|
return flagNotSetError{flagText: flagType}
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.updateList,
|
resourceList: c.updateList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -58,7 +58,7 @@ func (c *updateCommand) Execute() error {
|
||||||
|
|
||||||
func (c *updateCommand) updateList(gtsClient *client.Client) error {
|
func (c *updateCommand) updateList(gtsClient *client.Client) error {
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := gtsClient.GetList(c.listID)
|
list, err := gtsClient.GetList(c.listID)
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
module enbas-build
|
|
||||||
|
|
||||||
go 1.22.0
|
|
||||||
|
|
||||||
require github.com/magefile/mage v1.15.0
|
|
8
mage
8
mage
|
@ -1,8 +0,0 @@
|
||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
cd ./internal/build
|
|
||||||
mage $@
|
|
5
magefiles/go.mod
Normal file
5
magefiles/go.mod
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
module codeflow.dananglin.me.uk/apollo/enbas/magefiles
|
||||||
|
|
||||||
|
go 1.22.3
|
||||||
|
|
||||||
|
require github.com/magefile/mage v1.15.0
|
|
@ -29,10 +29,6 @@ var Default = Build
|
||||||
// To enable verbose mode set ENBAS_TEST_VERBOSE=1.
|
// To enable verbose mode set ENBAS_TEST_VERBOSE=1.
|
||||||
// To enable coverage mode set ENBAS_TEST_COVER=1.
|
// To enable coverage mode set ENBAS_TEST_COVER=1.
|
||||||
func Test() error {
|
func Test() error {
|
||||||
if err := changeToProjectRoot(); err != nil {
|
|
||||||
return fmt.Errorf("unable to change to the project's root directory; %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
goTest := sh.RunCmd("go", "test")
|
goTest := sh.RunCmd("go", "test")
|
||||||
|
|
||||||
args := []string{"./..."}
|
args := []string{"./..."}
|
||||||
|
@ -50,10 +46,6 @@ func Test() error {
|
||||||
|
|
||||||
// Lint runs golangci-lint against the code.
|
// Lint runs golangci-lint against the code.
|
||||||
func Lint() error {
|
func Lint() error {
|
||||||
if err := changeToProjectRoot(); err != nil {
|
|
||||||
return fmt.Errorf("unable to change to the project's root directory; %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sh.RunV("golangci-lint", "run", "--color", "always")
|
return sh.RunV("golangci-lint", "run", "--color", "always")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,10 +53,6 @@ func Lint() error {
|
||||||
// To rebuild packages that are already up-to-date set ENBAS_BUILD_REBUILD_ALL=1
|
// To rebuild packages that are already up-to-date set ENBAS_BUILD_REBUILD_ALL=1
|
||||||
// To enable verbose mode set ENBAS_BUILD_VERBOSE=1
|
// To enable verbose mode set ENBAS_BUILD_VERBOSE=1
|
||||||
func Build() error {
|
func Build() error {
|
||||||
if err := changeToProjectRoot(); err != nil {
|
|
||||||
return fmt.Errorf("unable to change to the project's root directory; %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
main := "./cmd/" + app
|
main := "./cmd/" + app
|
||||||
binary := "./__build/" + app
|
binary := "./__build/" + app
|
||||||
flags := ldflags()
|
flags := ldflags()
|
||||||
|
@ -107,10 +95,6 @@ func Install() error {
|
||||||
|
|
||||||
// Clean clean the workspace.
|
// Clean clean the workspace.
|
||||||
func Clean() error {
|
func Clean() error {
|
||||||
if err := changeToProjectRoot(); err != nil {
|
|
||||||
return fmt.Errorf("unable to change to the project's root directory; %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := sh.Rm(app); err != nil {
|
if err := sh.Rm(app); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -122,14 +106,6 @@ func Clean() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func changeToProjectRoot() error {
|
|
||||||
if err := os.Chdir("../.."); err != nil {
|
|
||||||
return fmt.Errorf("unable to change directory; %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ldflags returns the build flags.
|
// ldflags returns the build flags.
|
||||||
func ldflags() string {
|
func ldflags() string {
|
||||||
ldflagsfmt := "-s -w -X main.binaryVersion=%s -X main.gitCommit=%s -X main.goVersion=%s -X main.buildTime=%s"
|
ldflagsfmt := "-s -w -X main.binaryVersion=%s -X main.gitCommit=%s -X main.goVersion=%s -X main.buildTime=%s"
|
Loading…
Reference in a new issue