Skip to content

Commit

Permalink
Add collector names into usage of collector flag
Browse files Browse the repository at this point in the history
  • Loading branch information
nocturnalastro authored and crwr45 committed Jun 26, 2023
1 parent f100f70 commit 6f1a5b9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 9 additions & 1 deletion pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
package cmd

import (
"fmt"
"os"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -115,6 +117,12 @@ func init() { //nolint:funlen // Allow this to get a little long
"collector",
"s",
defaultCollectorNames,
"the collectors you wish to run default is all",
fmt.Sprintf(
"the collectors you wish to run (case-insensitive):\n"+
"\trequired collectors: %s (will be automatically added)\n"+
"\toptional collectors: %s",
strings.Join(runner.RequiredCollectorNames, ", "),
strings.Join(runner.OptionalCollectorNames, ", "),
),
)
}
14 changes: 7 additions & 7 deletions pkg/runner/collector_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import (
)

var (
optionalCollectorNames []string
requiredCollectorNames []string
OptionalCollectorNames []string
RequiredCollectorNames []string
All string = "all"
)

func init() {
optionalCollectorNames = []string{collectors.DPLLCollectorName, collectors.GPSCollectorName}
requiredCollectorNames = []string{collectors.DevInfoCollectorName}
OptionalCollectorNames = []string{collectors.DPLLCollectorName, collectors.GPSCollectorName}
RequiredCollectorNames = []string{collectors.DevInfoCollectorName}
}

func isIn(name string, arr []string) bool {
Expand All @@ -45,16 +45,16 @@ func removeDuplicates(arr []string) []string {
// are returned
func GetCollectorsToRun(selectedCollectors []string) []string {
collectorNames := make([]string, 0)
collectorNames = append(collectorNames, requiredCollectorNames...)
collectorNames = append(collectorNames, RequiredCollectorNames...)
for _, name := range selectedCollectors {
switch {
case strings.EqualFold(name, "all"):
collectorNames = append(collectorNames, optionalCollectorNames...)
collectorNames = append(collectorNames, OptionalCollectorNames...)
collectorNames = removeDuplicates(collectorNames)
return collectorNames
case isIn(name, collectorNames):
continue
case isIn(name, optionalCollectorNames):
case isIn(name, OptionalCollectorNames):
collectorNames = append(collectorNames, name)
default:
log.Errorf("Unknown collector %s. Ignored", name)
Expand Down

0 comments on commit 6f1a5b9

Please sign in to comment.