refactoring and formatting changes

This commit is contained in:
Dan Anglin 2024-05-31 10:27:10 +01:00
parent fc3109df02
commit 78745ab072
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
6 changed files with 16 additions and 15 deletions

View file

@ -64,13 +64,15 @@ func run() error {
}
flag.StringVar(&topLevelFlags.ConfigDir, "config-dir", "", "specify your config directory")
flag.BoolFunc("no-color", "disable ANSI colours when displaying text on screen", func(value string) error {
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)
}
topLevelFlags.NoColor = new(bool)
*topLevelFlags.NoColor = boolVal
return nil
})

View file

@ -112,7 +112,7 @@ func (c *CreateExecutor) createList(gtsClient *client.Client) error {
}
fmt.Println("Successfully created the following list:")
fmt.Printf("\n%s\n", list)
utilities.Display(list, *c.topLevelFlags.NoColor)
return nil
}
@ -193,7 +193,7 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
}
fmt.Println("Successfully created the following status:")
fmt.Println(status)
utilities.Display(status, *c.topLevelFlags.NoColor)
return nil
}

View file

@ -6,6 +6,7 @@ import (
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
)
type EditExecutor struct {
@ -40,7 +41,7 @@ func (e *EditExecutor) Execute() error {
}
funcMap := map[string]func(*client.Client) error{
resourceList: e.updateList,
resourceList: e.editList,
}
doFunc, ok := funcMap[e.resourceType]
@ -56,7 +57,7 @@ func (e *EditExecutor) Execute() error {
return doFunc(gtsClient)
}
func (e *EditExecutor) updateList(gtsClient *client.Client) error {
func (e *EditExecutor) editList(gtsClient *client.Client) error {
if e.listID == "" {
return FlagNotSetError{flagText: flagListID}
}
@ -85,7 +86,7 @@ func (e *EditExecutor) updateList(gtsClient *client.Client) error {
}
fmt.Println("Successfully updated the list.")
fmt.Println(updatedList)
utilities.Display(updatedList, *e.topLevelFlags.NoColor)
return nil
}

View file

@ -83,7 +83,7 @@ func (c *ShowExecutor) showInstance(gtsClient *client.Client) error {
return fmt.Errorf("unable to retrieve the instance details; %w", err)
}
fmt.Println(instance)
utilities.Display(instance, *c.topLevelFlags.NoColor)
return nil
}
@ -155,7 +155,7 @@ func (c *ShowExecutor) showStatus(gtsClient *client.Client) error {
return nil
}
fmt.Println(status)
utilities.Display(status, *c.topLevelFlags.NoColor)
return nil
}
@ -243,8 +243,7 @@ func (c *ShowExecutor) showLists(gtsClient *client.Client) error {
return nil
}
fmt.Println(utilities.HeaderFormat(true, "LISTS"))
fmt.Println(lists)
utilities.Display(lists, *c.topLevelFlags.NoColor)
return nil
}

View file

@ -121,12 +121,12 @@ func (l List) Display(noColor bool) string {
type Lists []List
func (l Lists) String() string {
output := ""
func (l Lists) Display(noColor bool) string {
output := "\n" + utilities.HeaderFormat(noColor, "LISTS")
for i := range l {
output += fmt.Sprintf(
"\n%s (%s)",
"\n%s (%s)",
l[i].Title,
l[i].ID,
)

View file

@ -173,8 +173,7 @@ func (s Status) Display(noColor bool) string {
%s
%s
%s
`
%s`
return fmt.Sprintf(
format,