示例#1
0
文件: goss.go 项目: postfix/goss
func main() {
	app := cli.NewApp()
	app.EnableBashCompletion = true
	app.Version = version
	app.Name = "goss"
	app.Usage = "Quick and Easy server validation"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "gossfile, f",
			Value:  "./goss.json",
			Usage:  "Goss file to read from / write to",
			EnvVar: "GOSS_FILE",
		},
		cli.StringFlag{
			Name:  "package",
			Usage: "Package type to use [rpm, deb]",
		},
	}
	app.Commands = []cli.Command{
		{
			Name:    "validate",
			Aliases: []string{"v"},
			Usage:   "Validate system",
			Action: func(c *cli.Context) {
				goss.Run(c.GlobalString("gossfile"), c)
			},
		},
		{
			Name:    "render",
			Aliases: []string{"r"},
			Usage:   "render gossfile after imports",
			Action: func(c *cli.Context) {
				fmt.Print(goss.RenderJSON(c.GlobalString("gossfile")))
			},
		},
		{
			Name:    "add",
			Aliases: []string{"a"},
			Usage:   "add a resource to the test suite",
			Subcommands: []cli.Command{
				{
					Name:  "package",
					Usage: "add new package",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Package", c.Args().First(), c)
					},
				},
				{
					Name:  "file",
					Usage: "add new file",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "File", c.Args().First(), c)
					},
				},
				{
					Name:  "addr",
					Usage: "add new remote address:port - ex: google.com:80",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Addr", c.Args().First(), c)
					},
				},
				{
					Name:  "port",
					Usage: "add new listening [protocol]:port - ex: 80 or udp:123",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Port", c.Args().First(), c)
					},
				},
				{
					Name:  "service",
					Usage: "add new service",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Service", c.Args().First(), c)
					},
				},
				{
					Name:  "user",
					Usage: "add new user",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "User", c.Args().First(), c)
					},
				},
				{
					Name:  "group",
					Usage: "add new group",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Group", c.Args().First(), c)
					},
				},
				{
					Name:  "command",
					Usage: "add new command",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Command", c.Args().First(), c)
					},
				},
				{
					Name:  "dns",
					Usage: "add new dns",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "DNS", c.Args().First(), c)
					},
				},
				{
					Name:  "process",
					Usage: "add new process name",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Process", c.Args().First(), c)
					},
				},
				{
					Name:  "goss",
					Usage: "add new goss file",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Gossfile", c.Args().First(), c)
					},
				},
			},
		},
	}

	app.Run(os.Args)

}
示例#2
0
文件: goss.go 项目: lacion/goss
func main() {
	startTime := time.Now()
	app := cli.NewApp()
	app.EnableBashCompletion = true
	app.Version = version
	app.Name = "goss"
	app.Usage = "Quick and Easy server validation"
	app.Flags = []cli.Flag{
		cli.StringFlag{
			Name:   "gossfile, g",
			Value:  "./goss.json",
			Usage:  "Goss file to read from / write to",
			EnvVar: "GOSS_FILE",
		},
		cli.StringFlag{
			Name:  "package",
			Usage: "Package type to use [rpm, deb, alpine]",
		},
	}
	app.Commands = []cli.Command{
		{
			Name:    "validate",
			Aliases: []string{"v"},
			Usage:   "Validate system",
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:   "format, f",
					Value:  "rspecish",
					Usage:  fmt.Sprintf("Format to output in, valid options: %s", outputs.Outputers()),
					EnvVar: "GOSS_FMT",
				},
				cli.BoolFlag{
					Name:   "no-color",
					Usage:  "Force color off",
					EnvVar: "GOSS_NOCOLOR",
				},
			},
			Action: func(c *cli.Context) {
				goss.Run(c, startTime)
			},
		},
		{
			Name:    "render",
			Aliases: []string{"r"},
			Usage:   "render gossfile after imports",
			Action: func(c *cli.Context) {
				fmt.Print(goss.RenderJSON(c.GlobalString("gossfile")))
			},
		},
		{
			Name:    "autoadd",
			Aliases: []string{"aa"},
			Usage:   "automatically add all matching resource to the test suite",
			Action: func(c *cli.Context) {
				goss.AutoAppendResource(c.GlobalString("gossfile"), c.Args().First(), c)
			},
		},
		{
			Name:    "add",
			Aliases: []string{"a"},
			Usage:   "add a resource to the test suite",
			Flags: []cli.Flag{
				cli.StringSliceFlag{
					Name:  "exclude-attr",
					Usage: "Exclude the following attributes when adding a new resource",
				},
			},
			Subcommands: []cli.Command{
				{
					Name:  "package",
					Usage: "add new package",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Package", c.Args().First(), c)
					},
				},
				{
					Name:  "file",
					Usage: "add new file",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "File", c.Args().First(), c)
					},
				},
				{
					Name:  "addr",
					Usage: "add new remote address:port - ex: google.com:80",
					Flags: []cli.Flag{
						cli.DurationFlag{
							Name:  "timeout",
							Value: 500 * time.Millisecond,
						},
					},
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Addr", c.Args().First(), c)
					},
				},
				{
					Name:  "port",
					Usage: "add new listening [protocol]:port - ex: 80 or udp:123",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Port", c.Args().First(), c)
					},
				},
				{
					Name:  "service",
					Usage: "add new service",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Service", c.Args().First(), c)
					},
				},
				{
					Name:  "user",
					Usage: "add new user",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "User", c.Args().First(), c)
					},
				},
				{
					Name:  "group",
					Usage: "add new group",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Group", c.Args().First(), c)
					},
				},
				{
					Name:  "command",
					Usage: "add new command",
					Flags: []cli.Flag{
						cli.DurationFlag{
							Name:  "timeout",
							Value: 10 * time.Second,
						},
					},
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Command", c.Args().First(), c)
					},
				},
				{
					Name:  "dns",
					Usage: "add new dns",
					Flags: []cli.Flag{
						cli.DurationFlag{
							Name:  "timeout",
							Value: 500 * time.Millisecond,
						},
					},
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "DNS", c.Args().First(), c)
					},
				},
				{
					Name:  "process",
					Usage: "add new process name",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Process", c.Args().First(), c)
					},
				},
				{
					Name:  "goss",
					Usage: "add new goss file",
					Action: func(c *cli.Context) {
						goss.AppendResource(c.GlobalString("gossfile"), "Gossfile", c.Args().First(), c)
					},
				},
			},
		},
	}

	app.Run(os.Args)

}