github.com/AiRISTAFlowInc/fs-cli@v0.2.6/commands/install.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  
     8  	"github.com/AiRISTAFlowInc/fs-cli/api"
     9  	"github.com/AiRISTAFlowInc/fs-cli/common"
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  var replaceContrib string
    14  var contribBundleFile string
    15  
    16  func init() {
    17  	installCmd.Flags().StringVarP(&replaceContrib, "replace", "r", "", "specify path to replacement contribution/dependency")
    18  	installCmd.Flags().StringVarP(&contribBundleFile, "file", "f", "", "specify contribution bundle")
    19  	rootCmd.AddCommand(installCmd)
    20  }
    21  
    22  var installCmd = &cobra.Command{
    23  	Use:   "install [flags] <contribution|dependency>",
    24  	Short: "install a flogo contribution/dependency",
    25  	Long:  "Installs a flogo contribution or dependency",
    26  	Run: func(cmd *cobra.Command, args []string) {
    27  		if contribBundleFile != "" {
    28  			err := api.InstallContribBundle(common.CurrentProject(), contribBundleFile)
    29  			if err != nil {
    30  				fmt.Fprintf(os.Stderr, "Error installing contribution bundle: %v\n", err)
    31  				os.Exit(1)
    32  			}
    33  		}
    34  
    35  		if replaceContrib != "" {
    36  			replaceContrib = strings.Replace(replaceContrib, "@", " ", -1)
    37  			err := api.InstallReplacedPackage(common.CurrentProject(), replaceContrib, args[0])
    38  			if err != nil {
    39  				fmt.Fprintf(os.Stderr, "Error installing contribution/dependency: %v\n", err)
    40  				os.Exit(1)
    41  			}
    42  		} else {
    43  			for _, pkg := range args {
    44  				err := api.InstallPackage(common.CurrentProject(), pkg)
    45  				if err != nil {
    46  					fmt.Fprintf(os.Stderr, "Error installing contribution/dependency: %v\n", err)
    47  					os.Exit(1)
    48  				}
    49  			}
    50  		}
    51  	},
    52  }