Skip to content

Commit

Permalink
Fix command line flags parsing
Browse files Browse the repository at this point in the history
Unfortunately we'll need separate flags for "fetch all" behavior,
otherwise we can't handle both cases with one flag and default library.

Closes: #4
  • Loading branch information
amnk committed Feb 14, 2018
1 parent 5981562 commit d919d3b
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,13 @@ func (i *Item) renderElement(config LocalConfig) {

func main() {
var dashboards = flag.String("dashboards", "-1",
"IDs of dashboards, separated by comma. If nothing is given, all dashboards are parsed")
"IDs of dashboards, separated by comma")
var all_dashboards = flag.Bool("all_dashboards", false,
"If set, all dashobards will be exported.")
var monitors = flag.String("monitors", "-1",
"IDs of monitors, separated by comma. If nothing is given, all monitors are exported")
"IDs of monitors, separated by comma")
var all_monitors = flag.Bool("all_monitors", false,
"If set, all monitors will be exported.")
var files = flag.Bool("files", false, "Create file for each entity instead of stdout dump")

flag.Parse()
Expand All @@ -142,26 +146,26 @@ func main() {
files: *files,
}

//Keeps a list of dashboard IDs as ints
if ! (*dashboards == "-1") {
if len(*dashboards) == 0 {
config.items = append(config.items, getAllDashboards(config.client)...)
} else {
for _, element := range strings.Split(*dashboards, ",") {
dash, _ := strconv.Atoi(element)
config.items = append(config.items, Item{id: dash, d: Dashboard{}})
}
if (*all_dashboards) && !(*dashboards == "-1") {
log.Fatalf("Either dashboards or all_dashboards can be used.")
} else if (*all_dashboards) {
config.items = append(config.items, getAllDashboards(config.client)...)
} else if ! (*dashboards == "-1") {
for _, element := range strings.Split(*dashboards, ",") {
dash, _ := strconv.Atoi(element)
config.items = append(config.items, Item{id: dash, d: Dashboard{}})
}

}

if ! (*monitors == "-1") {
if len(*monitors) == 0 {
config.items = append(config.items, getAllMonitors(config.client)...)
} else {
for _, element := range strings.Split(*monitors, ",") {
mon, _ := strconv.Atoi(element)
config.items = append(config.items, Item{id: mon, d: Monitor{}})
}
if (*all_monitors) && !(*monitors == "-1") {
log.Fatalf("Either monitors or all_monitors can be used.")
} else if (*all_monitors) {
config.items = append(config.items, getAllMonitors(config.client)...)
} else if ! (*monitors == "-1") {
for _, element := range strings.Split(*monitors, ",") {
mon, _ := strconv.Atoi(element)
config.items = append(config.items, Item{id: mon, d: Monitor{}})
}
}

Expand Down

0 comments on commit d919d3b

Please sign in to comment.