Esempio n. 1
0
func addSubCommand(app *kingpin.Application, name string, description string) {
	c := app.Command(name, description).Action(func(c *kingpin.ParseContext) error {
		fmt.Printf("Would have run command %s.\n", name)
		return nil
	})
	c.Flag("nop-flag", "Example of a flag with no options").Bool()
}
Esempio n. 2
0
func configureNetcatCommand(app *kingpin.Application) {
	c := &NetcatCommand{}
	nc := app.Command("nc", "Connect to a Host").Action(c.run)
	nc.Flag("nop-flag", "Example of a flag with no options").Bool()

	// You can provide hint options using a function to generate them
	nc.Flag("host", "Provide a hostname to nc").
		Required().
		HintAction(listHosts).
		StringVar(&c.hostName)

	// You can provide hint options statically
	nc.Flag("port", "Provide a port to connect to").
		Required().
		HintOptions("80", "443", "8080").
		IntVar(&c.port)

	// Enum/EnumVar options will be turned into completion options automatically
	nc.Flag("format", "Define the output format").
		Default("raw").
		EnumVar(&c.format, "raw", "json")

	// You can combine HintOptions with HintAction too
	nc.Flag("host-with-multi", "Define a hostname").
		HintAction(listHosts).
		HintOptions("myhost.com").
		String()

	// And combine with themselves
	nc.Flag("host-with-multi-options", "Define a hostname").
		HintOptions("myhost.com").
		HintOptions("myhost2.com").
		String()

	// If you specify HintOptions/HintActions for Enum/EnumVar, the options
	// provided for Enum/EnumVar will be overridden.
	nc.Flag("format-with-override-1", "Define a format").
		HintAction(listHosts).
		Enum("option1", "option2")

	nc.Flag("format-with-override-2", "Define a format").
		HintOptions("myhost.com", "myhost2.com").
		Enum("option1", "option2")
}
Esempio n. 3
0
func configureCmdList(app *kingpin.Application) {
	c := &ListCommand{}
	l := app.Command("list", "List all the caches and their status").Action(c.Run)
	l.Flag("file", "Cache configuration file").Default(".cache.yml").OverrideDefaultFromEnvar("CACHE_FILE").StringVar(&c.File)
	l.Flag("dir", "The directory to cache into").Default("/var/tmp/cache").OverrideDefaultFromEnvar("CACHE_DIR").StringVar(&c.Directory)
}
Esempio n. 4
0
func configureLsCommand(app *kingpin.Application) {
	c := &LsCommand{}
	ls := app.Command("ls", "List files.").Action(c.run)
	ls.Flag("all", "List all files.").Short('a').BoolVar(&c.All)
}
Esempio n. 5
0
func configureCmdSnapshot(app *kingpin.Application) {
	c := &SnapshotCommand{}
	s := app.Command("snapshot", "Take a snapshot of the current directories").Action(c.Run)
	s.Flag("file", "Cache configuration file").Default(".cache.yml").OverrideDefaultFromEnvar("CACHE_FILE").StringVar(&c.File)
	s.Flag("dir", "The directory to cache into").Default("/var/tmp/cache").OverrideDefaultFromEnvar("CACHE_DIR").StringVar(&c.Directory)
}