-
Notifications
You must be signed in to change notification settings - Fork 338
/
init.go
48 lines (42 loc) · 1.4 KB
/
init.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*----------------------------------------------------------------
* Copyright (c) ThoughtWorks, Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE in the project root for license information.
*----------------------------------------------------------------*/
package cmd
import (
"fmt"
"github.com/getgauge/gauge/template"
"github.com/getgauge/gauge/projectInit"
"github.com/spf13/cobra"
)
var (
initCmd = &cobra.Command{
Use: "init <template> [flags]",
Short: "Initialize project structure in the current directory",
Long: `Initialize project structure in the current directory.`,
Example: ` gauge init java
gauge init https://github.com/getgauge/template-js/releases/latest/download/js.zip
gauge init /Users/user/Download/foo.zip`,
Run: func(cmd *cobra.Command, args []string) {
if templates {
l, err := template.All()
if err != nil {
exit(fmt.Errorf("failed to get templates. %w", err), cmd.UsageString())
}
fmt.Println(l)
} else {
if len(args) < 1 {
exit(fmt.Errorf("missing argument <template name, URL or filepath>. To see all the templates, run 'gauge init -t'"), cmd.UsageString())
}
projectInit.Template(args[0], machineReadable)
}
},
DisableAutoGenTag: true,
}
templates bool
)
func init() {
GaugeCmd.AddCommand(initCmd)
initCmd.Flags().BoolVarP(&templates, "templates", "t", false, "Lists all available templates")
}