Skip to content

Commit

Permalink
Merge pull request #304 from hgsgtk/refactor/filepath
Browse files Browse the repository at this point in the history
define default file name while doMonitorsPull() at once
  • Loading branch information
yseto committed Jul 1, 2020
2 parents 898fdd5 + ef0237b commit 5b0102a
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions monitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ var commandMonitors = cli.Command{
},
}

func monitorSaveRules(rules []mackerel.Monitor, optFilePath string) error {
filePath := "monitors.json"
if optFilePath != "" {
filePath = optFilePath
}
func monitorSaveRules(rules []mackerel.Monitor, filePath string) error {
file, err := os.Create(filePath)
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -172,15 +168,15 @@ func doMonitorsPull(c *cli.Context) error {
monitors, err := mackerelclient.NewFromContext(c).FindMonitors()
logger.DieIf(err)

if filePath == "" {
filePath = "monitors.json"
}
monitorSaveRules(monitors, filePath)

if isVerbose {
format.PrettyPrintJSON(os.Stdout, monitors)
}

if filePath == "" {
filePath = "monitors.json"
}
logger.Log("info", fmt.Sprintf("Monitor rules are saved to '%s' (%d rules).", filePath, len(monitors)))
return nil
}
Expand Down

0 comments on commit 5b0102a

Please sign in to comment.