github.com/getgauge/gauge@v1.6.9/cmd/config.go (about)

     1  /*----------------------------------------------------------------
     2   *  Copyright (c) ThoughtWorks, Inc.
     3   *  Licensed under the Apache License, Version 2.0
     4   *  See LICENSE in the project root for license information.
     5   *----------------------------------------------------------------*/
     6  
     7  package cmd
     8  
     9  import (
    10  	"errors"
    11  	"github.com/getgauge/gauge/config"
    12  	"github.com/getgauge/gauge/logger"
    13  	"github.com/spf13/cobra"
    14  )
    15  
    16  var (
    17  	configCmd = &cobra.Command{
    18  		Use:     "config [flags] [args]",
    19  		Short:   "Change global configurations",
    20  		Long:    `Change global configurations.`,
    21  		Example: `  gauge config check_updates false`,
    22  		Run: func(cmd *cobra.Command, args []string) {
    23  			if list || machineReadable {
    24  				text, err := config.List(machineReadable)
    25  				if err != nil {
    26  					logger.Fatal(true, err.Error())
    27  				}
    28  				logger.Info(true, text)
    29  				return
    30  			}
    31  			if len(args) == 0 {
    32  				exit(errors.New("Config command needs argument(s)."), cmd.UsageString())
    33  			}
    34  			if len(args) == 1 {
    35  				text, err := config.GetProperty(args[0])
    36  				if err != nil {
    37  					logger.Fatal(true, err.Error())
    38  				}
    39  				logger.Info(true, text)
    40  				return
    41  			}
    42  			if err := config.Update(args[0], args[1]); err != nil {
    43  				logger.Fatal(true, err.Error())
    44  			}
    45  		},
    46  		DisableAutoGenTag: true,
    47  	}
    48  	list bool
    49  )
    50  
    51  func init() {
    52  	GaugeCmd.AddCommand(configCmd)
    53  	configCmd.Flags().BoolVarP(&list, "list", "", false, "List all global properties")
    54  	configCmd.Flags().BoolVarP(&machineReadable, "machine-readable", "m", false, "Print all properties in JSON format")
    55  }