gitee.com/mirrors/gauge@v1.0.6/cmd/update.go (about)

     1  // Copyright 2015 ThoughtWorks, Inc.
     2  
     3  // This file is part of Gauge.
     4  
     5  // Gauge is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  
    10  // Gauge is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  // GNU General Public License for more details.
    14  
    15  // You should have received a copy of the GNU General Public License
    16  // along with Gauge.  If not, see <http://www.gnu.org/licenses/>.
    17  
    18  package cmd
    19  
    20  import (
    21  	"fmt"
    22  
    23  	"github.com/getgauge/gauge/plugin/install"
    24  	"github.com/spf13/cobra"
    25  )
    26  
    27  var (
    28  	updateCmd = &cobra.Command{
    29  		Use:   "update [flags] <plugin>",
    30  		Short: "Updates a plugin",
    31  		Long:  `Updates a plugin.`,
    32  		Example: `  gauge update java
    33    gauge update -a
    34    gauge update -c`,
    35  		Run: func(cmd *cobra.Command, args []string) {
    36  			if all {
    37  				install.UpdatePlugins(machineReadable)
    38  				return
    39  			} else if check {
    40  				install.PrintUpdateInfoWithDetails()
    41  				return
    42  			}
    43  			if len(args) < 1 {
    44  				exit(fmt.Errorf("missing argument <plugin name>"), cmd.UsageString())
    45  			}
    46  			install.HandleUpdateResult(install.Plugin(args[0], pVersion, machineReadable), args[0], true)
    47  		},
    48  		DisableAutoGenTag: true,
    49  	}
    50  	all   bool
    51  	check bool
    52  )
    53  
    54  func init() {
    55  	GaugeCmd.AddCommand(updateCmd)
    56  	updateCmd.Flags().BoolVarP(&all, "all", "a", false, "Updates all the installed Gauge plugins")
    57  	updateCmd.Flags().BoolVarP(&check, "check", "c", false, "Checks for Gauge and plugins updates")
    58  }