[minor] add -a flag for mig-cmd that can be used to print action json

This commit is contained in:
Aaron Meihm 2015-09-04 13:41:31 -05:00
Родитель 64200c0789
Коммит 376d1acc7d
2 изменённых файлов: 30 добавлений и 0 удалений

Просмотреть файл

@ -330,3 +330,13 @@ func (a Action) PrintCounters() {
}
fmt.Fprintf(os.Stderr, "%s\n", out)
}
// Return the an indented JSON string representing the action suitable for
// display
func (a Action) IndentedString() (string, error) {
buf, err := json.MarshalIndent(a, "", " ")
if err != nil {
return "", err
}
return string(buf), nil
}

Просмотреть файл

@ -28,6 +28,7 @@ usage: %s <module> <global options> <module parameters>
--- Global options ---
-a <bool> display action json that would be used and exit
-c <path> path to an alternative config file. If not set, use ~/.migrc
-e <duration> time after which the action expires. 60 seconds by default.
example: -e 300s (5 minutes)
@ -75,6 +76,7 @@ func main() {
op mig.Operation
a mig.Action
migrc, show, render, target, expiration, afile string
showaction bool
verbose bool
modargs []string
run interface{}
@ -87,6 +89,7 @@ func main() {
homedir := client.FindHomedir()
fs := flag.NewFlagSet("mig flag", flag.ContinueOnError)
fs.Usage = continueOnFlagError
fs.BoolVar(&showaction, "a", false, "display action json that would be used and exit")
fs.StringVar(&migrc, "c", homedir+"/.migrc", "alternative configuration file")
fs.StringVar(&show, "show", "found", "type of results to show")
fs.StringVar(&render, "render", "text", "results rendering mode")
@ -121,6 +124,14 @@ func main() {
panic(err)
}
fmt.Fprintf(os.Stderr, "[info] launching action from file, all flags are ignored\n")
if showaction {
actionstr, err := a.IndentedString()
if err != nil {
panic(err)
}
fmt.Fprintf(os.Stdout, "%v\n", actionstr)
os.Exit(0)
}
goto readytolaunch
}
@ -208,6 +219,15 @@ func main() {
}
a.Target = target
if showaction {
actionstr, err := a.IndentedString()
if err != nil {
panic(err)
}
fmt.Fprintf(os.Stdout, "%v\n", actionstr)
os.Exit(0)
}
readytolaunch:
// instanciate an API client
conf, err = client.ReadConfiguration(migrc)