From 78745ab0727fbb6a57ada51f57e14189520acdea Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Fri, 31 May 2024 10:27:10 +0100 Subject: [PATCH] refactoring and formatting changes --- cmd/enbas/main.go | 4 +++- internal/executor/create.go | 4 ++-- internal/executor/{update.go => edit.go} | 7 ++++--- internal/executor/show.go | 7 +++---- internal/model/list.go | 6 +++--- internal/model/status.go | 3 +-- 6 files changed, 16 insertions(+), 15 deletions(-) rename internal/executor/{update.go => edit.go} (91%) diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index 92476d0..0e27f0e 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -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 }) diff --git a/internal/executor/create.go b/internal/executor/create.go index c847a0c..e7f1ac5 100644 --- a/internal/executor/create.go +++ b/internal/executor/create.go @@ -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 } diff --git a/internal/executor/update.go b/internal/executor/edit.go similarity index 91% rename from internal/executor/update.go rename to internal/executor/edit.go index a3517c0..9d92bd3 100644 --- a/internal/executor/update.go +++ b/internal/executor/edit.go @@ -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 } diff --git a/internal/executor/show.go b/internal/executor/show.go index fb50636..2661d0e 100644 --- a/internal/executor/show.go +++ b/internal/executor/show.go @@ -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 } diff --git a/internal/model/list.go b/internal/model/list.go index a9f6a94..c29d235 100644 --- a/internal/model/list.go +++ b/internal/model/list.go @@ -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, ) diff --git a/internal/model/status.go b/internal/model/status.go index 3d68744..599e66b 100644 --- a/internal/model/status.go +++ b/internal/model/status.go @@ -173,8 +173,7 @@ func (s Status) Display(noColor bool) string { %s %s - %s -` + %s` return fmt.Sprintf( format,