github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/delete-image.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 rmiCmd = &cobra.Command{
    14  	Use:     "delete-image",
    15  	Aliases: []string{"rmi"},
    16  	Short:   "Delete a unikernel image",
    17  	Long: `Deletes an image.
    18  You may specify the image by name or id.`,
    19  	Run: func(cmd *cobra.Command, args []string) {
    20  		if err := func() error {
    21  			if err := readClientConfig(); err != nil {
    22  				return err
    23  			}
    24  			if imageName == "" {
    25  				return errors.New("must specify --image", nil)
    26  			}
    27  			if host == "" {
    28  				host = clientConfig.Host
    29  			}
    30  			logrus.WithFields(logrus.Fields{"host": host, "force": force, "image": imageName}).Info("deleting image")
    31  			if err := client.UnikClient(host).Images().Delete(imageName, force); err != nil {
    32  				return err
    33  			}
    34  			return nil
    35  		}(); err != nil {
    36  			logrus.Errorf("failed deleting image: %v", err)
    37  			os.Exit(-1)
    38  		}
    39  	},
    40  }
    41  
    42  func init() {
    43  	RootCmd.AddCommand(rmiCmd)
    44  	rmiCmd.Flags().StringVar(&imageName, "image", "", "<string,required> name or id of image. unik accepts a prefix of the name or id")
    45  	rmiCmd.Flags().BoolVar(&force, "force", false, "<bool, optional> force deleting image in the case that it is running")
    46  }