forked from eljuanchosf/ansible-gen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
101 lines (92 loc) · 2.27 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"os"
"time"
"github.com/thiagoalmeidasa/ansible-gen/ansibleGen"
"github.com/urfave/cli"
)
var cliVersion string
func main() {
app := cli.NewApp()
app.Name = "ansible-gen"
app.Version = cliVersion
app.Compiled = time.Now()
app.Authors = []cli.Author{
cli.Author{
Name: "Juan Pablo Genovese",
Email: "[email protected]",
},
}
app.Copyright = "(c) 2016 Juan Pablo Genovese"
app.HelpName = "ansible-gen"
app.Usage = "Generates and scaffolds Ansible projects and roles"
var customRoles string
var galaxyRoles string
var skipGit bool
var dryRun bool
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "dry-run, d",
Usage: "just print results, do not modify the filesystem",
Destination: &dryRun,
},
}
app.Commands = []cli.Command{
{
Name: "project",
Aliases: []string{"p"},
Usage: "Creates a new Ansible project",
Flags: []cli.Flag{
cli.StringFlag{
Name: "c",
Value: "",
Usage: "A comma separated list of the custom roles for the project",
Destination: &customRoles,
},
cli.StringFlag{
Name: "g",
Value: "",
Usage: "A comma separated list of the Ansible Galaxy roles for the project",
Destination: &galaxyRoles,
},
cli.BoolFlag{
Name: "skip-git",
Usage: "Do not initialize a Git repository for the project",
Destination: &skipGit,
},
},
Action: func(c *cli.Context) error {
projectName := c.Args().First()
if projectName == "" {
fmt.Println("Please provide a project name")
cli.ShowSubcommandHelp(c)
return nil
}
ansibleProject := *ansibleGen.NewAnsibleProject(projectName, customRoles, galaxyRoles)
ansibleProject.Save(dryRun)
if !skipGit {
ansibleProject.InitGit(dryRun)
}
return nil
},
},
{
Name: "role",
Aliases: []string{"r"},
Usage: "Creates a new Ansible role",
Action: func(c *cli.Context) error {
roleName := c.Args().First()
if c.Args().First() == "" {
fmt.Println("Please provide a role name")
cli.ShowSubcommandHelp(c)
return nil
}
ansibleRole := *ansibleGen.NewAnsibleRole(roleName)
ansibleRole.Save(dryRun)
return nil
},
},
}
app.Run(os.Args)
}