github.com/emc-advanced-dev/unik@v0.0.0-20190717152701-a58d3e8e33b7/cmd/providers.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  
     8  	"github.com/sirupsen/logrus"
     9  	"github.com/spf13/cobra"
    10  
    11  	"github.com/emc-advanced-dev/pkg/errors"
    12  	"github.com/solo-io/unik/pkg/client"
    13  )
    14  
    15  var providersCmd = &cobra.Command{
    16  	Use:   "providers",
    17  	Short: "List available unikernel providers",
    18  	Long:  `Returns a list of providers available to the targeted unik backend.`,
    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 providers")
    28  			providers, err := client.UnikClient(host).AvailableProviders()
    29  			if err != nil {
    30  				return errors.New("listing providers failed", err)
    31  			}
    32  			fmt.Printf("%s\n", strings.Join(providers, "\n"))
    33  			return nil
    34  		}(); err != nil {
    35  			logrus.Errorf("failed listing providers: %v", err)
    36  			os.Exit(-1)
    37  		}
    38  	},
    39  }
    40  
    41  func init() {
    42  	RootCmd.AddCommand(providersCmd)
    43  }