github.com/getgauge/gauge@v1.6.9/cmd/install.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  	"github.com/getgauge/gauge/config"
    11  	"github.com/getgauge/gauge/logger"
    12  	"github.com/getgauge/gauge/plugin/install"
    13  	"github.com/spf13/cobra"
    14  )
    15  
    16  var (
    17  	installCmd = &cobra.Command{
    18  		Use:   "install [flags] [plugin]",
    19  		Short: "Download and install plugin(s)",
    20  		Long:  `Download and install specified plugin or all plugins in the project's 'manifest.json' file.`,
    21  		Example: `  gauge install
    22    gauge install java
    23    gauge install java -f gauge-java-0.6.3-darwin.x86_64.zip`,
    24  		Run: func(cmd *cobra.Command, args []string) {
    25  			if len(args) < 1 {
    26  				install.AllPlugins(machineReadable, false)
    27  				return
    28  			}
    29  			if zip != "" {
    30  				install.HandleInstallResult(install.InstallPluginFromZipFile(zip, args[0]), args[0], true)
    31  			} else {
    32  				install.HandleInstallResult(install.Plugin(args[0], pVersion, machineReadable), args[0], true)
    33  			}
    34  			if err := config.SetProjectRoot(args); err == nil {
    35  				if err := install.AddPluginToProject(args[0]); err != nil {
    36  					logger.Fatalf(true, "Failed to add plugin %s to project : %s\n", args[0], err.Error())
    37  				}
    38  			}
    39  		},
    40  		DisableAutoGenTag: true,
    41  	}
    42  	zip      string
    43  	pVersion string
    44  )
    45  
    46  func init() {
    47  	GaugeCmd.AddCommand(installCmd)
    48  	installCmd.Flags().StringVarP(&zip, "file", "f", "", "Installs the plugin from zip file")
    49  	installCmd.Flags().StringVarP(&pVersion, "version", "v", "", "Version of plugin to be installed")
    50  }