checkpoint: add support for the NO_COLOR variable
This commit is contained in:
parent
29d6ca600f
commit
fc3109df02
3 changed files with 33 additions and 11 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/executor"
|
||||
)
|
||||
|
@ -57,10 +58,21 @@ func run() error {
|
|||
commandUnblock: "unblock a resource (e.g. an account)",
|
||||
}
|
||||
|
||||
topLevelFlags := executor.TopLevelFlags{}
|
||||
topLevelFlags := executor.TopLevelFlags{
|
||||
ConfigDir: "",
|
||||
NoColor: nil,
|
||||
}
|
||||
|
||||
flag.StringVar(&topLevelFlags.ConfigDir, "config-dir", "", "specify your config directory")
|
||||
flag.BoolVar(&topLevelFlags.NoColor, "no-color", false, "disable ANSI colours when displaying text on screen")
|
||||
flag.BoolFunc("no-color", "disable ANSI colours 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)
|
||||
}
|
||||
topLevelFlags.NoColor = new(bool)
|
||||
*topLevelFlags.NoColor = boolVal
|
||||
return nil
|
||||
})
|
||||
|
||||
flag.Usage = usageFunc(commandSummaries)
|
||||
|
||||
|
@ -72,6 +84,16 @@ func run() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// If NoColor is still unspecified, check to see if the NO_COLOR environment variable is set
|
||||
if topLevelFlags.NoColor == nil {
|
||||
topLevelFlags.NoColor = new(bool)
|
||||
if os.Getenv("NO_COLOR") != "" {
|
||||
*topLevelFlags.NoColor = true
|
||||
} else {
|
||||
*topLevelFlags.NoColor = false
|
||||
}
|
||||
}
|
||||
|
||||
command := flag.Arg(0)
|
||||
args := flag.Args()[1:]
|
||||
|
||||
|
|
|
@ -18,5 +18,5 @@ func (a *AccountNames) Set(value string) error {
|
|||
|
||||
type TopLevelFlags struct {
|
||||
ConfigDir string
|
||||
NoColor bool
|
||||
NoColor *bool
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ func (c *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
utilities.Display(account, c.topLevelFlags.NoColor)
|
||||
utilities.Display(account, *c.topLevelFlags.NoColor)
|
||||
|
||||
if !c.myAccount && !c.skipAccountRelationship {
|
||||
relationship, err := gtsClient.GetAccountRelationship(account.ID)
|
||||
|
@ -124,7 +124,7 @@ func (c *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
|||
return fmt.Errorf("unable to retrieve the relationship to this account; %w", err)
|
||||
}
|
||||
|
||||
utilities.Display(relationship, c.topLevelFlags.NoColor)
|
||||
utilities.Display(relationship, *c.topLevelFlags.NoColor)
|
||||
}
|
||||
|
||||
if c.myAccount && c.showUserPreferences {
|
||||
|
@ -133,7 +133,7 @@ func (c *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
|||
return fmt.Errorf("unable to retrieve the user preferences; %w", err)
|
||||
}
|
||||
|
||||
utilities.Display(preferences, c.topLevelFlags.NoColor)
|
||||
utilities.Display(preferences, *c.topLevelFlags.NoColor)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -197,7 +197,7 @@ func (c *ShowExecutor) showTimeline(gtsClient *client.Client) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
utilities.Display(timeline, c.topLevelFlags.NoColor)
|
||||
utilities.Display(timeline, *c.topLevelFlags.NoColor)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ func (c *ShowExecutor) showList(gtsClient *client.Client) error {
|
|||
list.Accounts = accountMap
|
||||
}
|
||||
|
||||
utilities.Display(list, c.topLevelFlags.NoColor)
|
||||
utilities.Display(list, *c.topLevelFlags.NoColor)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ func (c *ShowExecutor) showFollowers(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
if len(followers.Accounts) > 0 {
|
||||
utilities.Display(followers, c.topLevelFlags.NoColor)
|
||||
utilities.Display(followers, *c.topLevelFlags.NoColor)
|
||||
} else {
|
||||
fmt.Println("There are no followers for this account or the list is hidden.")
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ func (c *ShowExecutor) showFollowing(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
if len(following.Accounts) > 0 {
|
||||
utilities.Display(following, c.topLevelFlags.NoColor)
|
||||
utilities.Display(following, *c.topLevelFlags.NoColor)
|
||||
} else {
|
||||
fmt.Println("This account is not following anyone or the list is hidden.")
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ func (c *ShowExecutor) showBlocked(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
if len(blocked.Accounts) > 0 {
|
||||
utilities.Display(blocked, c.topLevelFlags.NoColor)
|
||||
utilities.Display(blocked, *c.topLevelFlags.NoColor)
|
||||
} else {
|
||||
fmt.Println("You have no blocked accounts.")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue