diff --git a/main.go b/main.go index f8d66e5..ba4554b 100644 --- a/main.go +++ b/main.go @@ -2,7 +2,9 @@ package main import ( "bufio" + "encoding/json" "fmt" + "io/ioutil" "log" "os" "strings" @@ -59,6 +61,27 @@ func cleanup(c *cli.Context) error { return nil } +// Export ConfigletBuilder +func export(c *cli.Context) error { + cvpClient := c.App.Metadata["client"].(*client.CvpClient) + reader := bufio.NewReader(os.Stdin) + fmt.Print("Builder Name: ") + response, err := reader.ReadString('\n') + if err != nil { + log.Fatal(err) + } + response = strings.TrimSpace(response) + builder, err := cvpClient.API.GetConfigletBuilderByName(response) + if err != nil { + log.Fatal(err) + } + fmt.Println(builder) + fout, _ := json.MarshalIndent(builder, "", " ") + _ = ioutil.WriteFile("test.json", fout, 0644) + + return nil +} + // Login to CVP func login(c *cli.Context) error { ip := c.String("ip") @@ -123,6 +146,12 @@ func main() { Usage: "Cleanup unused configlets in CloudVision", Action: cleanup, }, + { + Before: login, + Name: "export", + Usage: "Export ConfigletBuilder", + Action: export, + }, }, } if err := app.Run(os.Args); err != nil {