github.com/henvic/wedeploycli@v1.7.6-0.20200319005353-3630f582f284/command/inspect/config/config.go (about)

     1  package inspectconfig
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"strings"
     7  
     8  	"github.com/henvic/wedeploycli/command/internal/we"
     9  	"github.com/henvic/wedeploycli/config"
    10  	"github.com/henvic/wedeploycli/inspector"
    11  	"github.com/spf13/cobra"
    12  )
    13  
    14  // ConfigCmd for "lcp inspect config"
    15  var ConfigCmd = &cobra.Command{
    16  	Use:   "config",
    17  	Short: "Get config info",
    18  	Args:  cobra.NoArgs,
    19  	RunE:  runE,
    20  }
    21  
    22  var (
    23  	format         string
    24  	showTypeFields bool
    25  )
    26  
    27  func init() {
    28  	ConfigCmd.Flags().StringVarP(&format, "format", "f", "", "Format the output using the given go template")
    29  	ConfigCmd.Flags().BoolVar(&showTypeFields, "fields", false, "Show type field names")
    30  }
    31  
    32  func runE(cmd *cobra.Command, args []string) (err error) {
    33  	if showTypeFields && format != "" {
    34  		return errors.New("incompatible use: --fields and --format cannot be used together")
    35  	}
    36  
    37  	if showTypeFields {
    38  		// TODO(henvic): consider to expose *remotes.List primitives
    39  		var i = config.Params{}
    40  		fmt.Println(strings.Join(inspector.GetSpec(i), "\n"))
    41  		return nil
    42  	}
    43  
    44  	wectx := we.Context()
    45  
    46  	var inspectMsg, inspectErr = inspector.InspectConfig(format, wectx)
    47  
    48  	if inspectErr != nil {
    49  		return inspectErr
    50  	}
    51  
    52  	fmt.Printf("%v\n", inspectMsg)
    53  	return nil
    54  }