github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/start-instance.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/emc-advanced-dev/pkg/errors" 10 "github.com/solo-io/unik/pkg/client" 11 ) 12 13 var startCmd = &cobra.Command{ 14 Use: "start", 15 Short: "Start a stopped unikernel instance", 16 Long: `Starts a stopped instance. 17 You may specify the instance by name or id.`, 18 Run: func(cmd *cobra.Command, args []string) { 19 if err := func() error { 20 if err := readClientConfig(); err != nil { 21 return err 22 } 23 if host == "" { 24 host = clientConfig.Host 25 } 26 if instanceName == "" { 27 return errors.New("must specify --instance", nil) 28 } 29 logrus.WithFields(logrus.Fields{"host": host, "instance": instanceName}).Info("starting instance") 30 if err := client.UnikClient(host).Instances().Start(instanceName); err != nil { 31 return err 32 } 33 return nil 34 }(); err != nil { 35 logrus.Errorf("failed starting instance: %v", err) 36 os.Exit(-1) 37 } 38 }, 39 } 40 41 func init() { 42 RootCmd.AddCommand(startCmd) 43 startCmd.Flags().StringVar(&instanceName, "instance", "", "<string,required> name or id of instance. unik accepts a prefix of the name or id") 44 }