Exemple #1
0
func newCertAction(c *cli.Context) {

	if len(c.Args()) != 1 {
		fmt.Fprintln(os.Stderr, "cert file must be provided.")
		os.Exit(1)
	}

	certFileName := c.Args()[0]
	years := c.Int("years")
	bits := c.Int("key-bits")

	if c.IsSet("passphrase") {

	}

	ips := c.String("ips")
	ipArray := strings.Split(ips, ",")

	certFile := certFileName + crtSuffix
	keyFile := certFileName + "-key" + crtSuffix
	caFile := caPrefix + crtSuffix
	caKeyFile := caKeyPrefix + crtSuffix
	org := c.String("organization")
	commonName := c.String("common-name")

	err := utils.GenerateCert(ipArray, d.Path(certFile), d.Path(keyFile), d.Path(caFile), d.Path(caKeyFile), org, commonName, years, bits)
	if err != nil {
		fmt.Fprintln(os.Stderr, "Create Servcer cert error:", err)
		os.Exit(1)
	} else {
		fmt.Println("Create server/key complete")
	}

}
Exemple #2
0
func TestApp_RunAsSubcommandParseFlags(t *testing.T) {
	var context *cli.Context

	a := cli.NewApp()
	a.Commands = []cli.Command{
		{
			Name: "foo",
			Action: func(c *cli.Context) {
				context = c
			},
			Flags: []cli.Flag{
				cli.StringFlag{
					Name:  "lang",
					Value: "english",
					Usage: "language for the greeting",
				},
			},
			Before: func(_ *cli.Context) error { return nil },
		},
	}
	a.Run([]string{"", "foo", "--lang", "spanish", "abcd"})

	expect(t, context.Args().Get(0), "abcd")
	expect(t, context.String("lang"), "spanish")
}