github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/instances.go (about) 1 package cmd 2 3 import ( 4 "os" 5 6 "github.com/sirupsen/logrus" 7 "github.com/spf13/cobra" 8 9 "github.com/solo-io/unik/pkg/client" 10 ) 11 12 var psCmd = &cobra.Command{ 13 Use: "instances", 14 Aliases: []string{"ps"}, 15 Short: "List pending/running/stopped unik instances", 16 Long: `Lists all unik-managed instances across providers.`, 17 Run: func(cmd *cobra.Command, args []string) { 18 if err := func() error { 19 if err := readClientConfig(); err != nil { 20 return err 21 } 22 if host == "" { 23 host = clientConfig.Host 24 } 25 logrus.WithField("host", host).Info("listing instances") 26 instances, err := client.UnikClient(host).Instances().All() 27 if err != nil { 28 return err 29 } 30 printInstances(instances...) 31 return nil 32 }(); err != nil { 33 logrus.Errorf("failed listing instances: %v", err) 34 os.Exit(-1) 35 } 36 }, 37 } 38 39 func init() { 40 RootCmd.AddCommand(psCmd) 41 }