Skip to content

Commit

Permalink
inventory - add themes and no-notes switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Glonek committed Sep 12, 2024
1 parent 7deb8b2 commit 6307cb5
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/7.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ _Release Date: Month Day, Year_
* AWS: Expiry System: cleanup unused SSH keys.
* AWS: `template vacuum` also vacuum template temporary SSH keys.
* CI: Update all dependencies: brew install actions, rpm package, golang version and Packages.
* CLI: Add theme support for all inventory listings with `--theme=box|frame|nocolor` 3 options; allow `--no-notes` to disable extra notes
* Client: Add eks client - eksctl bootstrap system.
* Client: Open ports 8998 and 8182 for Vector and Graph clients.
* Client: Vector: add support for centos-stream-9 base.
Expand Down
4 changes: 2 additions & 2 deletions src/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ type backend interface {
// returns a map of [int]string for a given cluster, where int is node number and string is the IP of said node
GetNodeIpMap(name string, internalIPs bool) (map[int]string, error)
// return formatted for printing cluster list
ClusterListFull(json bool, owner string, noPager bool, isPretty bool, sort []string, renderer string) (string, error)
ClusterListFull(json bool, owner string, noPager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error)
// return formatted for printing template list
TemplateListFull(json bool, noPager bool, isPretty bool, sort []string, renderer string) (string, error)
TemplateListFull(json bool, noPager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error)
// upload files to node
Upload(clusterName string, node int, source string, destination string, verbose bool, legacy bool) error
// download files from node
Expand Down
8 changes: 6 additions & 2 deletions src/backendAws.go
Original file line number Diff line number Diff line change
Expand Up @@ -2646,22 +2646,26 @@ func (d *backendAws) GetInstanceTags(name string) (map[string]map[string]string,
return nodeList, nil
}

func (d *backendAws) ClusterListFull(isJson bool, owner string, pager bool, isPretty bool, sort []string, renderer string) (string, error) {
func (d *backendAws) ClusterListFull(isJson bool, owner string, pager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error) {
a.opts.Inventory.List.Json = isJson
a.opts.Inventory.List.Owner = owner
a.opts.Inventory.List.Pager = pager
a.opts.Inventory.List.JsonPretty = isPretty
a.opts.Inventory.List.SortBy = sort
a.opts.Inventory.List.RenderType = renderer
a.opts.Inventory.List.Theme = theme
a.opts.Inventory.List.NoNotes = noNotes
return "", a.opts.Inventory.List.run(d.server, d.client, false, false, false)
}

func (d *backendAws) TemplateListFull(isJson bool, pager bool, isPretty bool, sort []string, renderer string) (string, error) {
func (d *backendAws) TemplateListFull(isJson bool, pager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error) {
a.opts.Inventory.List.Json = isJson
a.opts.Inventory.List.Pager = pager
a.opts.Inventory.List.JsonPretty = isPretty
a.opts.Inventory.List.SortBy = sort
a.opts.Inventory.List.RenderType = renderer
a.opts.Inventory.List.Theme = theme
a.opts.Inventory.List.NoNotes = noNotes
return "", a.opts.Inventory.List.run(false, false, true, false, false)
}

Expand Down
8 changes: 6 additions & 2 deletions src/backendDocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,21 +1298,25 @@ func (d *backendDocker) copyFilesToContainer(name string, files []fileListReader
}

// returns an unformatted string with list of clusters, to be printed to user
func (d *backendDocker) ClusterListFull(isJson bool, owner string, pager bool, isPretty bool, sort []string, renderer string) (string, error) {
func (d *backendDocker) ClusterListFull(isJson bool, owner string, pager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error) {
a.opts.Inventory.List.Json = isJson
a.opts.Inventory.List.Pager = pager
a.opts.Inventory.List.JsonPretty = isPretty
a.opts.Inventory.List.SortBy = sort
a.opts.Inventory.List.RenderType = renderer
a.opts.Inventory.List.Theme = theme
a.opts.Inventory.List.NoNotes = noNotes
return "", a.opts.Inventory.List.run(d.server, d.client, false, false, false)
}

// returns an unformatted string with list of clusters, to be printed to user
func (d *backendDocker) TemplateListFull(isJson bool, pager bool, isPretty bool, sort []string, renderer string) (string, error) {
func (d *backendDocker) TemplateListFull(isJson bool, pager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error) {
a.opts.Inventory.List.Json = isJson
a.opts.Inventory.List.Pager = pager
a.opts.Inventory.List.JsonPretty = isPretty
a.opts.Inventory.List.SortBy = sort
a.opts.Inventory.List.RenderType = renderer
a.opts.Inventory.List.Theme = theme
a.opts.Inventory.List.NoNotes = noNotes
return "", a.opts.Inventory.List.run(false, false, true, false, false)
}
8 changes: 6 additions & 2 deletions src/backendGcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -1705,13 +1705,15 @@ func (d *backendGcp) GetNodeIpMap(name string, internalIPs bool) (map[int]string
return nlist, nil
}

func (d *backendGcp) ClusterListFull(isJson bool, owner string, pager bool, isPretty bool, sort []string, renderer string) (string, error) {
func (d *backendGcp) ClusterListFull(isJson bool, owner string, pager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error) {
a.opts.Inventory.List.Json = isJson
a.opts.Inventory.List.Owner = owner
a.opts.Inventory.List.Pager = pager
a.opts.Inventory.List.JsonPretty = isPretty
a.opts.Inventory.List.SortBy = sort
a.opts.Inventory.List.RenderType = renderer
a.opts.Inventory.List.Theme = theme
a.opts.Inventory.List.NoNotes = noNotes
return "", a.opts.Inventory.List.run(d.server, d.client, false, false, false)
}

Expand Down Expand Up @@ -2375,12 +2377,14 @@ func (d *backendGcp) VacuumTemplates() error {
return d.vacuum(nil)
}

func (d *backendGcp) TemplateListFull(isJson bool, pager bool, isPretty bool, sort []string, renderer string) (string, error) {
func (d *backendGcp) TemplateListFull(isJson bool, pager bool, isPretty bool, sort []string, renderer string, theme string, noNotes bool) (string, error) {
a.opts.Inventory.List.Json = isJson
a.opts.Inventory.List.Pager = pager
a.opts.Inventory.List.JsonPretty = isPretty
a.opts.Inventory.List.SortBy = sort
a.opts.Inventory.List.RenderType = renderer
a.opts.Inventory.List.Theme = theme
a.opts.Inventory.List.NoNotes = noNotes
return "", a.opts.Inventory.List.run(false, false, true, false, false)
}

Expand Down
4 changes: 3 additions & 1 deletion src/cmdClientList.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
type clientListCmd struct {
Owner string `long:"owner" description:"Only show resources tagged with this owner"`
SortBy []string `long:"sort-by" description:"sort by field name; must match exact header name; can be specified multiple times; format: asc:name dsc:name ascnum:name dscnum:name"`
Theme string `long:"theme" description:"for standard output, pick a theme: default|nocolor|frame|box"`
NoNotes bool `long:"no-notes" description:"for standard output, do not print extra notes below the tables"`
Json bool `short:"j" long:"json" description:"Provide output in json format"`
JsonPretty bool `short:"p" long:"pretty" description:"Provide json output with line-feeds and indentations"`
Pager bool `long:"pager" description:"set to enable vertical and horizontal pager" simplemode:"false"`
Expand Down Expand Up @@ -65,7 +67,7 @@ func (c *clientListCmd) Execute(args []string) error {
}
return nil
}
f, e := b.ClusterListFull(c.Json, c.Owner, c.Pager, c.JsonPretty, c.SortBy, c.RenderType)
f, e := b.ClusterListFull(c.Json, c.Owner, c.Pager, c.JsonPretty, c.SortBy, c.RenderType, c.Theme, c.NoNotes)
if e != nil {
return e
}
Expand Down
4 changes: 3 additions & 1 deletion src/cmdClusterList.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
type clusterListCmd struct {
Owner string `long:"owner" description:"Only show resources tagged with this owner"`
SortBy []string `long:"sort-by" description:"sort by field name; must match exact header name; can be specified multiple times; format: asc:name dsc:name ascnum:name dscnum:name"`
Theme string `long:"theme" description:"for standard output, pick a theme: default|nocolor|frame|box"`
NoNotes bool `long:"no-notes" description:"for standard output, do not print extra notes below the tables"`
Json bool `short:"j" long:"json" description:"Provide output in json format"`
JsonPretty bool `short:"p" long:"pretty" description:"Provide json output with line-feeds and indentations"`
Pager bool `long:"pager" description:"set to enable vertical and horizontal pager" simplemode:"false"`
Expand Down Expand Up @@ -63,7 +65,7 @@ func (c *clusterListCmd) Execute(args []string) error {
}
return nil
}
f, e := b.ClusterListFull(c.Json, c.Owner, c.Pager, c.JsonPretty, c.SortBy, c.RenderType)
f, e := b.ClusterListFull(c.Json, c.Owner, c.Pager, c.JsonPretty, c.SortBy, c.RenderType, c.Theme, c.NoNotes)
if e != nil {
return e
}
Expand Down
59 changes: 42 additions & 17 deletions src/cmdInventoryList.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type inventoryListCmd struct {
Owner string `long:"owner" description:"Only show resources tagged with this owner"`
Pager bool `long:"pager" description:"set to enable vertical and horizontal pager" simplemode:"false"`
SortBy []string `long:"sort-by" description:"sort by field name; must match exact header name; can be specified multiple times; format: asc:name dsc:name ascnum:name dscnum:name"`
Theme string `long:"theme" description:"for standard output, pick a theme: default|nocolor|frame|box"`
NoNotes bool `long:"no-notes" description:"for standard output, do not print extra notes below the tables"`
Json bool `short:"j" long:"json" description:"Provide output in json format"`
JsonPretty bool `short:"p" long:"pretty" description:"Provide json output with line-feeds and indentations"`
AWSFull bool `long:"aws-full" description:"set to iterate through all regions and provide full output"`
Expand Down Expand Up @@ -523,6 +525,9 @@ func (c *inventoryListCmd) run(showClusters bool, showClients bool, showTemplate
warnExp := colorPrint{c: text.Colors{text.BgHiYellow, text.FgBlack}, enable: true}
errExp := colorPrint{c: text.Colors{text.BgHiRed, text.FgWhite}, enable: true}
isColor := true
if c.Theme == "nocolor" || c.Theme == "frame" || c.Theme == "box" {
isColor = false
}
if _, ok := os.LookupEnv("NO_COLOR"); ok || os.Getenv("CLICOLOR") == "0" {
isColor = false
}
Expand Down Expand Up @@ -561,9 +566,20 @@ func (c *inventoryListCmd) run(showClusters bool, showClients bool, showTemplate
colorHiWhite.enable = false
warnExp.enable = false
errExp.enable = false
tstyle := t.Style()
tstyle.Options.DrawBorder = false
tstyle.Options.SeparateColumns = false
if c.Theme == "frame" {
t.SetStyle(table.StyleRounded)
tstyle := t.Style()
tstyle.Options.DrawBorder = true
tstyle.Options.SeparateColumns = false
} else if c.Theme == "box" {
t.SetStyle(table.StyleRounded)
tstyle := t.Style()
tstyle.Options.SeparateColumns = true
} else {
tstyle := t.Style()
tstyle.Options.DrawBorder = false
tstyle.Options.SeparateColumns = false
}
} else {
t.SetStyle(table.StyleColoredBlackOnCyanWhite)
}
Expand Down Expand Up @@ -716,12 +732,15 @@ func (c *inventoryListCmd) run(showClusters bool, showClients bool, showTemplate
t.AppendRow(vv)
}
fmt.Println(render())
if a.opts.Config.Backend.Type != "docker" {
fmt.Fprint(os.Stderr, "* instance Running Cost displays only the cost of owning the instance in a running state for the duration it was running so far. It does not account for taxes, disk, network or transfer costs.\n\n")
} else {
fmt.Fprint(os.Stderr, "* to connect directly to the cluster (non-docker-desktop), execute 'aerolab cluster list' and connect to the node IP on the given exposed port (or configured aerospike services port - default 3000)\n")
fmt.Fprint(os.Stderr, "* to connect to the cluster when using Docker Desktop, execute 'aerolab cluster list` and connect to IP 127.0.0.1:EXPOSED_PORT with a connect policy of `--services-alternate`\n\n")
if !c.NoNotes {
if a.opts.Config.Backend.Type != "docker" {
fmt.Fprint(os.Stdout, "* instance Running Cost displays only the cost of owning the instance in a running state for the duration it was running so far. It does not account for taxes, disk, network or transfer costs.\n")
} else {
fmt.Fprint(os.Stdout, "* to connect directly to the cluster (non-docker-desktop), execute 'aerolab cluster list' and connect to the node IP on the given exposed port (or configured aerospike services port - default 3000)\n")
fmt.Fprint(os.Stdout, "* to connect to the cluster when using Docker Desktop, execute 'aerolab cluster list` and connect to IP 127.0.0.1:EXPOSED_PORT with a connect policy of `--services-alternate`\n")
}
}
fmt.Println("")
}

if showClients {
Expand Down Expand Up @@ -784,11 +803,14 @@ func (c *inventoryListCmd) run(showClusters bool, showClients bool, showTemplate
t.AppendRow(vv)
}
fmt.Println(render())
if a.opts.Config.Backend.Type == "docker" {
fmt.Fprint(os.Stderr, "* if using Docker Desktop and forwaring ports by exposing them (-e ...), use IP 127.0.0.1 for the Access URL\n\n")
} else {
fmt.Fprint(os.Stderr, "* instance Running Cost displays only the cost of owning the instance in a running state for the duration it was running so far. It does not account for taxes, disk, network or transfer costs.\n\n")
if !c.NoNotes {
if a.opts.Config.Backend.Type == "docker" {
fmt.Fprint(os.Stdout, "* if using Docker Desktop and forwaring ports by exposing them (-e ...), use IP 127.0.0.1 for the Access URL\n")
} else {
fmt.Fprint(os.Stdout, "* instance Running Cost displays only the cost of owning the instance in a running state for the duration it was running so far. It does not account for taxes, disk, network or transfer costs.\n")
}
}
fmt.Println("")
}

for _, showOther := range showOthers {
Expand Down Expand Up @@ -1209,12 +1231,15 @@ func (c *inventoryListCmd) run(showClusters bool, showClients bool, showTemplate
}
}
fmt.Println(render())
if a.opts.Config.Backend.Type != "docker" {
fmt.Fprint(os.Stderr, "* instance Running Cost displays only the cost of owning the instance in a running state for the duration it was running so far. It does not account for taxes, disk, network or transfer costs.\n\n")
} else {
fmt.Fprint(os.Stderr, "* to connect directly to the cluster (non-docker-desktop), execute 'aerolab cluster list' and connect to the node IP on the given exposed port (or configured aerospike services port - default 3000)\n")
fmt.Fprint(os.Stderr, "* to connect to the cluster when using Docker Desktop, execute 'aerolab cluster list` and connect to IP 127.0.0.1:EXPOSED_PORT with a connect policy of `--services-alternate`\n\n")
if !c.NoNotes {
if a.opts.Config.Backend.Type != "docker" {
fmt.Fprint(os.Stdout, "* instance Running Cost displays only the cost of owning the instance in a running state for the duration it was running so far. It does not account for taxes, disk, network or transfer costs.\n")
} else {
fmt.Fprint(os.Stdout, "* to connect directly to the cluster (non-docker-desktop), execute 'aerolab cluster list' and connect to the node IP on the given exposed port (or configured aerospike services port - default 3000)\n")
fmt.Fprint(os.Stdout, "* to connect to the cluster when using Docker Desktop, execute 'aerolab cluster list` and connect to IP 127.0.0.1:EXPOSED_PORT with a connect policy of `--services-alternate`\n")
}
}
fmt.Println("")
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/cmdTemplateList.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import "fmt"

type templateListCmd struct {
SortBy []string `long:"sort-by" description:"sort by field name; must match exact header name; can be specified multiple times; format: asc:name dsc:name ascnum:name dscnum:name"`
Theme string `long:"theme" description:"for standard output, pick a theme: default|nocolor|frame|box"`
NoNotes bool `long:"no-notes" description:"for standard output, do not print extra notes below the tables"`
Json bool `short:"j" long:"json" description:"Provide output in json format"`
JsonPretty bool `short:"p" long:"pretty" description:"Provide json output with line-feeds and indentations"`
Pager bool `long:"pager" description:"set to enable vertical and horizontal pager"`
Expand All @@ -15,7 +17,7 @@ func (c *templateListCmd) Execute(args []string) error {
if earlyProcess(args) {
return nil
}
l, err := b.TemplateListFull(c.Json, c.Pager, c.JsonPretty, c.SortBy, c.RenderType)
l, err := b.TemplateListFull(c.Json, c.Pager, c.JsonPretty, c.SortBy, c.RenderType, c.Theme, c.NoNotes)
if err != nil {
return err
}
Expand Down

0 comments on commit 6307cb5

Please sign in to comment.