refactoring and formatting changes
This commit is contained in:
parent
fc3109df02
commit
78745ab072
6 changed files with 16 additions and 15 deletions
|
@ -64,13 +64,15 @@ func run() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.StringVar(&topLevelFlags.ConfigDir, "config-dir", "", "specify your config directory")
|
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)
|
boolVal, err := strconv.ParseBool(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to parse %q as a boolean; %w", value, err)
|
return fmt.Errorf("unable to parse %q as a boolean; %w", value, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
topLevelFlags.NoColor = new(bool)
|
topLevelFlags.NoColor = new(bool)
|
||||||
*topLevelFlags.NoColor = boolVal
|
*topLevelFlags.NoColor = boolVal
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ func (c *CreateExecutor) createList(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Successfully created the following list:")
|
fmt.Println("Successfully created the following list:")
|
||||||
fmt.Printf("\n%s\n", list)
|
utilities.Display(list, *c.topLevelFlags.NoColor)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,7 @@ func (c *CreateExecutor) createStatus(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Successfully created the following status:")
|
fmt.Println("Successfully created the following status:")
|
||||||
fmt.Println(status)
|
utilities.Display(status, *c.topLevelFlags.NoColor)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/utilities"
|
||||||
)
|
)
|
||||||
|
|
||||||
type EditExecutor struct {
|
type EditExecutor struct {
|
||||||
|
@ -40,7 +41,7 @@ func (e *EditExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
resourceList: e.updateList,
|
resourceList: e.editList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[e.resourceType]
|
doFunc, ok := funcMap[e.resourceType]
|
||||||
|
@ -56,7 +57,7 @@ func (e *EditExecutor) Execute() error {
|
||||||
return doFunc(gtsClient)
|
return doFunc(gtsClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EditExecutor) updateList(gtsClient *client.Client) error {
|
func (e *EditExecutor) editList(gtsClient *client.Client) error {
|
||||||
if e.listID == "" {
|
if e.listID == "" {
|
||||||
return FlagNotSetError{flagText: flagListID}
|
return FlagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
@ -85,7 +86,7 @@ func (e *EditExecutor) updateList(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Successfully updated the list.")
|
fmt.Println("Successfully updated the list.")
|
||||||
fmt.Println(updatedList)
|
utilities.Display(updatedList, *e.topLevelFlags.NoColor)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
|
@ -83,7 +83,7 @@ func (c *ShowExecutor) showInstance(gtsClient *client.Client) error {
|
||||||
return fmt.Errorf("unable to retrieve the instance details; %w", err)
|
return fmt.Errorf("unable to retrieve the instance details; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(instance)
|
utilities.Display(instance, *c.topLevelFlags.NoColor)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -155,7 +155,7 @@ func (c *ShowExecutor) showStatus(gtsClient *client.Client) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(status)
|
utilities.Display(status, *c.topLevelFlags.NoColor)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -243,8 +243,7 @@ func (c *ShowExecutor) showLists(gtsClient *client.Client) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(utilities.HeaderFormat(true, "LISTS"))
|
utilities.Display(lists, *c.topLevelFlags.NoColor)
|
||||||
fmt.Println(lists)
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,12 +121,12 @@ func (l List) Display(noColor bool) string {
|
||||||
|
|
||||||
type Lists []List
|
type Lists []List
|
||||||
|
|
||||||
func (l Lists) String() string {
|
func (l Lists) Display(noColor bool) string {
|
||||||
output := ""
|
output := "\n" + utilities.HeaderFormat(noColor, "LISTS")
|
||||||
|
|
||||||
for i := range l {
|
for i := range l {
|
||||||
output += fmt.Sprintf(
|
output += fmt.Sprintf(
|
||||||
"\n%s (%s)",
|
"\n • %s (%s)",
|
||||||
l[i].Title,
|
l[i].Title,
|
||||||
l[i].ID,
|
l[i].ID,
|
||||||
)
|
)
|
||||||
|
|
|
@ -173,8 +173,7 @@ func (s Status) Display(noColor bool) string {
|
||||||
%s
|
%s
|
||||||
|
|
||||||
%s
|
%s
|
||||||
%s
|
%s`
|
||||||
`
|
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
format,
|
format,
|
||||||
|
|
Loading…
Reference in a new issue