github.com/getgauge/gauge@v1.6.9/cmd/init.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  	"fmt"
    11  
    12  	"github.com/getgauge/gauge/template"
    13  
    14  	"github.com/getgauge/gauge/projectInit"
    15  	"github.com/spf13/cobra"
    16  )
    17  
    18  var (
    19  	initCmd = &cobra.Command{
    20  		Use:   "init <template> [flags]",
    21  		Short: "Initialize project structure in the current directory",
    22  		Long:  `Initialize project structure in the current directory.`,
    23  		Example: `  gauge init java
    24    gauge init https://github.com/getgauge/template-js/releases/latest/download/js.zip
    25    gauge init /Users/user/Download/foo.zip`,
    26  		Run: func(cmd *cobra.Command, args []string) {
    27  			if templates {
    28  				l, err := template.All()
    29  				if err != nil {
    30  					exit(fmt.Errorf("failed to get templates. %w", err), cmd.UsageString())
    31  				}
    32  				fmt.Println(l)
    33  			} else {
    34  				if len(args) < 1 {
    35  					exit(fmt.Errorf("missing argument <template name, URL or filepath>. To see all the templates, run 'gauge init -t'"), cmd.UsageString())
    36  				}
    37  				projectInit.Template(args[0], machineReadable)
    38  			}
    39  		},
    40  		DisableAutoGenTag: true,
    41  	}
    42  	templates bool
    43  )
    44  
    45  func init() {
    46  	GaugeCmd.AddCommand(initCmd)
    47  	initCmd.Flags().BoolVarP(&templates, "templates", "t", false, "Lists all available templates")
    48  }