Skip to content

Commit

Permalink
cscli metrics -> sort table order (#2908)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Mar 20, 2024
1 parent c76325b commit d9f2a22
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cmd/crowdsec-cli/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ func (ms metricStore) Format(out io.Writer, sections []string, formatType string

// if no sections are specified, we want all of them
if len(sections) == 0 {
for section := range ms {
sections = append(sections, section)
}
sections = maptools.SortedKeys(ms)
}

for _, section := range sections {
Expand All @@ -283,7 +281,7 @@ func (ms metricStore) Format(out io.Writer, sections []string, formatType string

switch formatType {
case "human":
for section := range want {
for _, section := range maptools.SortedKeys(want) {
want[section].Table(out, noUnit, showEmpty)
}
case "json":
Expand Down Expand Up @@ -376,7 +374,7 @@ cscli metrics list`,
}

// expandAlias returns a list of sections. The input can be a list of sections or alias.
func (cli *cliMetrics) expandSectionGroups(args []string) []string {
func (cli *cliMetrics) expandAlias(args []string) []string {
ret := []string{}

for _, section := range args {
Expand Down Expand Up @@ -422,7 +420,7 @@ cscli metrics show acquisition parsers scenarios stash -o json`,
// Positional args are optional
DisableAutoGenTag: true,
RunE: func(_ *cobra.Command, args []string) error {
args = cli.expandSectionGroups(args)
args = cli.expandAlias(args)
return cli.show(args, url, noUnit)
},
}
Expand Down

0 comments on commit d9f2a22

Please sign in to comment.