github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/images.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 imagesCmd = &cobra.Command{
    14  	Use:   "images",
    15  	Short: "List available unikernel images",
    16  	Long: `Lists all available unikernel images across providers.
    17  Includes important information for running and managing instances,
    18  including bind mounts required at runtime.`,
    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 host == "" {
    25  				host = clientConfig.Host
    26  			}
    27  			logrus.WithField("host", host).Info("listing images")
    28  			images, err := client.UnikClient(host).Images().All()
    29  			if err != nil {
    30  				return errors.New("listing images failed", err)
    31  			}
    32  			printImages(images...)
    33  			return nil
    34  		}(); err != nil {
    35  			logrus.Errorf("failed listing images: %v", err)
    36  			os.Exit(-1)
    37  		}
    38  	},
    39  }
    40  
    41  func init() {
    42  	RootCmd.AddCommand(imagesCmd)
    43  }