fix: use my-account flag for showing followers
Allow the use of the my-account flag when showing followers and following accounts for the authenticated user.
This commit is contained in:
parent
1a95384ba0
commit
de5cf65aa8
2 changed files with 63 additions and 17 deletions
|
@ -4,6 +4,10 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -136,3 +140,19 @@ func run() error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getMyAccount(gts *client.Client) (model.Account, error) {
|
||||||
|
authConfig, err := config.NewAuthenticationConfigFromFile()
|
||||||
|
if err != nil {
|
||||||
|
return model.Account{}, fmt.Errorf("unable to retrieve the authentication configuration; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
accountURI := authConfig.CurrentAccount
|
||||||
|
|
||||||
|
account, err := gts.GetAccount(accountURI)
|
||||||
|
if err != nil {
|
||||||
|
return model.Account{}, fmt.Errorf("unable to retrieve the account details; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return account, nil
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
||||||
)
|
)
|
||||||
|
@ -85,27 +84,28 @@ func (c *showCommand) showInstance(gts *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *showCommand) showAccount(gts *client.Client) error {
|
func (c *showCommand) showAccount(gts *client.Client) error {
|
||||||
var accountURI string
|
var (
|
||||||
|
account model.Account
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
if c.myAccount {
|
if c.myAccount {
|
||||||
authConfig, err := config.NewAuthenticationConfigFromFile()
|
account, err = getMyAccount(gts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve the authentication configuration; %w", err)
|
return fmt.Errorf("received an error while getting account details; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountURI = authConfig.CurrentAccount
|
|
||||||
} else {
|
} else {
|
||||||
if c.account == "" {
|
if c.account == "" {
|
||||||
return flagNotSetError{flagText: accountFlag}
|
return flagNotSetError{flagText: accountFlag}
|
||||||
}
|
}
|
||||||
|
|
||||||
accountURI = c.account
|
accountURI := c.account
|
||||||
}
|
|
||||||
|
|
||||||
account, err := gts.GetAccount(accountURI)
|
account, err = gts.GetAccount(accountURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve the account details; %w", err)
|
return fmt.Errorf("unable to retrieve the account details; %w", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Println(account)
|
fmt.Println(account)
|
||||||
|
|
||||||
|
@ -226,11 +226,24 @@ func (c *showCommand) showLists(gts *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *showCommand) showFollowers(gts *client.Client) error {
|
func (c *showCommand) showFollowers(gts *client.Client) error {
|
||||||
|
var accountID string
|
||||||
|
|
||||||
|
if c.myAccount {
|
||||||
|
account, err := getMyAccount(gts)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("received an error while getting account details; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
accountID = account.ID
|
||||||
|
} else {
|
||||||
if c.accountID == "" {
|
if c.accountID == "" {
|
||||||
return flagNotSetError{flagText: accountIDFlag}
|
return flagNotSetError{flagText: accountIDFlag}
|
||||||
}
|
}
|
||||||
|
|
||||||
followers, err := gts.GetFollowers(c.accountID, c.limit)
|
accountID = c.accountID
|
||||||
|
}
|
||||||
|
|
||||||
|
followers, err := gts.GetFollowers(accountID, c.limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve the list of followers; %w", err)
|
return fmt.Errorf("unable to retrieve the list of followers; %w", err)
|
||||||
}
|
}
|
||||||
|
@ -245,11 +258,24 @@ func (c *showCommand) showFollowers(gts *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *showCommand) showFollowing(gts *client.Client) error {
|
func (c *showCommand) showFollowing(gts *client.Client) error {
|
||||||
|
var accountID string
|
||||||
|
|
||||||
|
if c.myAccount {
|
||||||
|
account, err := getMyAccount(gts)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("received an error while getting account details; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
accountID = account.ID
|
||||||
|
} else {
|
||||||
if c.accountID == "" {
|
if c.accountID == "" {
|
||||||
return flagNotSetError{flagText: accountIDFlag}
|
return flagNotSetError{flagText: accountIDFlag}
|
||||||
}
|
}
|
||||||
|
|
||||||
following, err := gts.GetFollowing(c.accountID, c.limit)
|
accountID = c.accountID
|
||||||
|
}
|
||||||
|
|
||||||
|
following, err := gts.GetFollowing(accountID, c.limit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to retrieve the list of followed accounts; %w", err)
|
return fmt.Errorf("unable to retrieve the list of followed accounts; %w", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue