Example #1
1
// CreateComponentUsage creates a usage function for a component.
func createComponentUsage(info pythia.ComponentInfo, fs *flag.FlagSet) func() {
	return func() {
		fmt.Fprintf(os.Stderr, componentUsageHeader, os.Args[0], info.Name,
			info.Description)
		fs.PrintDefaults()
	}
}
Example #2
0
func (a *app) parseArgs(fs *flag.FlagSet, args []string) error {
	fs.SetOutput(a.out)
	fs.Usage = func() {
		fmt.Fprintf(a.out, help, args[0], args[0])
		fs.PrintDefaults()
	}

	fs.Var(&a.typeNames, "type",
		"A generated proto.Message type to generate stubs for (required, repeatable)")
	fs.StringVar(&a.outFile, "out", "proto_gae.gen.go",
		"The name of the output file")
	fs.StringVar(&a.header, "header", copyright, "Header text to put at the top of "+
		"the generated file. Defaults to the Chromium Authors copyright.")

	if err := fs.Parse(args[1:]); err != nil {
		return err
	}
	fail := errors.MultiError(nil)
	if a.typeNames.Data == nil || a.typeNames.Data.Len() == 0 {
		fail = append(fail, errors.New("must specify one or more -type"))
	}
	if !strings.HasSuffix(a.outFile, ".go") {
		fail = append(fail, errors.New("-output must end with '.go'"))
	}
	if len(fail) > 0 {
		for _, e := range fail {
			fmt.Fprintln(a.out, "error:", e)
		}
		fmt.Fprintln(a.out)
		fs.Usage()
		return fail
	}
	return nil
}
Example #3
0
func runAddBeer(command string, flags *flag.FlagSet, id string, date string, size string, days string, years string, count string, cellar *BeerCellar) {
	if command == "add" {
		if id != "" {
			if date == "" {
				date = time.Now().Format("02/01/06")
			}

			log.Printf("HERE %v and %v\n", days, years)

			if days != "" {
				cellar.AddBeerByDays(id, date, size, days, count)
				cellar.PrintCellar(&StdOutPrint{})
			} else if years != "" {
				log.Printf("ADDING BY YEARS\n")
				cellar.AddBeerByYears(id, date, size, years, count)
				cellar.PrintCellar(&StdOutPrint{})
			} else {
				box := cellar.AddBeer(id, date, size)
				print := &StdOutPrint{}
				box.PrintCellar(print)
			}
		} else {
			flags.SetOutput(os.Stdout)
			flags.PrintDefaults()
		}
	}

	cellar.printDiff()
}
Example #4
0
func getCmd(flagset *flag.FlagSet) {
	flagset.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s get [args...] key\n", os.Args[0])
		flagset.PrintDefaults()
	}
	flagset.StringVar(&secretKeyring, "secret-keyring", DefaultConfig.SecretKeyring, "path to armored secret keyring")
	flagset.Parse(os.Args[2:])
	key := flagset.Arg(0)
	if key == "" {
		flagset.Usage()
		os.Exit(1)
	}
	backendStore, err := getBackendStore(backendName, endpoint)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("Looking at consul node %q\n", nodeKey(key))
	if plaintext {
		value, err := getPlain(nodeKey(key), backendStore)
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("%s\n", value)
		return
	}
	value, err := getEncrypted(nodeKey(key), secretKeyring, backendStore)

	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("%s\n", value)
}
Example #5
0
func commandWorker(wi *Instance, wr *wrangler.Wrangler, args []string, cell string, runFromCli bool) (Worker, error) {
	action := args[0]

	actionLowerCase := strings.ToLower(action)
	for _, group := range commands {
		for _, cmd := range group.Commands {
			if strings.ToLower(cmd.Name) == actionLowerCase {
				var subFlags *flag.FlagSet
				if runFromCli {
					subFlags = flag.NewFlagSet(action, flag.ExitOnError)
				} else {
					subFlags = flag.NewFlagSet(action, flag.ContinueOnError)
				}
				// The command may be run from an RPC and may not log to the console.
				// The Wrangler logger defines where the output has to go.
				subFlags.SetOutput(logutil.NewLoggerWriter(wr.Logger()))
				subFlags.Usage = func() {
					wr.Logger().Printf("Usage: %s %s %s\n\n", os.Args[0], cmd.Name, cmd.Params)
					wr.Logger().Printf("%s\n\n", cmd.Help)
					subFlags.PrintDefaults()
				}
				return cmd.Method(wi, wr, subFlags, args[1:])
			}
		}
	}
	if runFromCli {
		flag.Usage()
	} else {
		PrintAllCommands(wr.Logger())
	}
	return nil, fmt.Errorf("unknown command: %v", action)
}
Example #6
0
File: cli.go Project: yuuki/go-cli
// Usage returns a usage documentation of a command.
func (c Command) Usage(flags *flag.FlagSet) string {
	usage := fmt.Sprintf("Usage: %s", c.Long)

	if flags == nil {
		return usage
	}

	var hasFlag bool
	flags.VisitAll(func(_ *flag.Flag) {
		hasFlag = true
	})

	if hasFlag == false {
		return usage
	}

	buf := bytes.NewBufferString(usage)
	buf.WriteString("\n\nOptions:\n")

	defer flags.SetOutput(nil)
	flags.SetOutput(buf)

	flags.PrintDefaults()

	return buf.String()
}
Example #7
0
func listCmd(flagset *flag.FlagSet) {
	flagset.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s list [args...] key\n", os.Args[0])
		flagset.PrintDefaults()
	}
	flagset.StringVar(&secretKeyring, "secret-keyring", ".secring.gpg", "path to armored secret keyring")
	flagset.Parse(os.Args[2:])
	key := flagset.Arg(0)
	if key == "" {
		flagset.Usage()
		os.Exit(1)
	}
	backendStore, err := getBackendStore(backendName, endpoint)
	if err != nil {
		log.Fatal(err)
	}
	if plaintext {
		list, err := listPlain(key, backendStore)
		if err != nil {
			log.Fatal(err)
		}
		for _, kv := range list {
			fmt.Printf("%s: %s", kv.Key, kv.Value)
		}
		return
	}
	list, err := listEncrypted(key, secretKeyring, backendStore)

	if err != nil {
		log.Fatal(err)
	}
	for _, kv := range list {
		fmt.Printf("%s: %s", kv.Key, kv.Value)
	}
}
Example #8
0
func usg(msg string, fs *flag.FlagSet) func() {
	return func() {
		fmt.Fprintf(os.Stderr, msg)
		fs.PrintDefaults()
		os.Exit(2)
	}
}
Example #9
0
func mainReqs(args []string, flags *flag.FlagSet) {
	flags.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage: %s %s <package-name>\n", os.Args[0], args[0])
		flags.PrintDefaults()
	}
	file := flags.String("graphfile", "", fmt.Sprintf("Path to PyPI dependency graph file.  Defaults to $GOPATH/src/github.com/beyang/cheerio/data/pypi_graph"))
	flags.Parse(args[1:])

	if flags.NArg() < 1 {
		flags.Usage()
		os.Exit(1)
	}

	pkg := cheerio.NormalizedPkgName(flags.Arg(0))

	var pypiG *cheerio.PyPIGraph
	if *file == "" {
		pypiG = cheerio.DefaultPyPIGraph
	} else {
		var err error
		pypiG, err = cheerio.NewPyPIGraph(*file)
		if err != nil {
			fmt.Printf("Error creating PyPI graph: %s\n", err)
			os.Exit(1)
		}
	}

	pkgReq := pypiG.Requires(pkg)
	pkgReqBy := pypiG.RequiredBy(pkg)
	fmt.Printf("pkg %s uses (%d):\n  %s\nand is used by (%d):\n  %s\n", pkg, len(pkgReq), strings.Join(pkgReq, " "), len(pkgReqBy), strings.Join(pkgReqBy, " "))
}
Example #10
0
func usage(err error, myflags *flag.FlagSet) {
	fmt.Fprintf(os.Stderr, "%s\n", err)

	fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
	myflags.PrintDefaults()
	os.Exit(1)
}
Example #11
0
File: cli.go Project: sdaros/passgo
func setUsage(fs *flag.FlagSet) {
	fs.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		fs.PrintDefaults()
		os.Exit(2)
	}
}
Example #12
0
// Returns a function that will print a help string
func printHelp(flags *flag.FlagSet) func() {
	return func() {
		fmt.Printf("usage: %s [--in=INPUT_IMAGE] [--out=OUTPUT_IMAGE] [options]\n", os.Args[0])

		fmt.Printf("\nOptions:\n")
		flags.PrintDefaults()
	}
}
Example #13
0
func printUsageAndExit(message string, flagSet *flag.FlagSet) {
	stderr.Printf("%s\n\n", message)
	stderr.Println("usage: confab COMMAND OPTIONS\n")
	stderr.Println("COMMAND: \"start\" or \"stop\"")
	stderr.Println("\nOPTIONS:")
	flagSet.PrintDefaults()
	stderr.Println()
	os.Exit(1)
}
Example #14
0
func runListBeers(command string, flags *flag.FlagSet, numBombers int, numSmall int, cellar *BeerCellar) {
	if command == "list" {
		if flags.Parsed() {
			cellar.PrintBeers(numBombers, numSmall)
		} else {
			flags.PrintDefaults()
		}
	}
}
Example #15
0
File: help.go Project: vadv/ostent
func UsageFunc(fs *flag.FlagSet) func() {
	return func() {
		// default usage
		fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
		fs.PrintDefaults() // flag.PrintDefaults()
		// continued usage:
		newHelp(os.Stderr).Run()
	}
}
Example #16
0
func initUsage(fs *flag.FlagSet) {
	fmt.Println("usage: git-bzr-bridge init [-h] <path>")
	fmt.Println("\nflags:")
	fs.SetOutput(os.Stdout)
	fs.PrintDefaults()

	fmt.Print(`
init will initialize a new repository at <path>
`)
}
Example #17
0
func updateHookUsage(fs *flag.FlagSet) {
	fmt.Println("usage: git-bzr-bridge update-hook [-h] <ref name> <old obj> <new obj>")
	fmt.Println("\nflags:")
	fs.SetOutput(os.Stdout)
	fs.PrintDefaults()

	fmt.Print(`
update 
`)
}
Example #18
0
func runSearch(command string, flags *flag.FlagSet, search string) {
	if command == "search" {
		if flags.Parsed() {
			matches := Search(search)
			for _, match := range matches {
				fmt.Printf("%v: %v\n", match.name, match.id)
			}
		} else {
			flags.PrintDefaults()
		}
	}
}
Example #19
0
//  Hook up the commandLineHelpUsage and commandLineHelpFooter strings
//  to the standard Go flag.Usage function.
func setupUsage(fs *flag.FlagSet) {
	printNonEmpty := func(s string) {
		if s != "" {
			fmt.Fprintf(os.Stderr, "%s\n", s)
		}
	}
	fs.Usage = func() {
		printNonEmpty(CommandLineHelpUsage)
		fs.PrintDefaults()
		printNonEmpty(CommandLineHelpFooter)
	}
}
Example #20
0
func branchesUsage(fs *flag.FlagSet) {
	fmt.Println("usage: git-bzr-bridge branches [-h] [-v]")
	fmt.Println("\nflags:")
	fs.SetOutput(os.Stdout)
	fs.PrintDefaults()

	fmt.Print(`
branches will list all branches known to git-bzr-bridge. Default output
format will list git branch references one per line. If -v is specified
it will also show Bzr urls and names of the (hidden) bzr branches.
`)
}
Example #21
0
func setCmd(flagset *flag.FlagSet) {
	flagset.Usage = func() {
		fmt.Fprintf(os.Stderr, "usage: %s set [args...] key file\n", os.Args[0])
		flagset.PrintDefaults()
	}
	flagset.StringVar(&keyring, "keyring", DefaultConfig.Keyring, "path to armored public keyring")
	flagset.Parse(os.Args[2:])
	key := flagset.Arg(0)
	if key == "" {
		flagset.Usage()
		os.Exit(1)
	}
	keySelector := make(pubkeyFilter, 1)
	p, node := path.Split(key)
	for dir := strings.TrimRight(p, "/"); dir != node && dir != "" && dir != "/"; dir, _ = path.Split(p) {
		p = strings.TrimRight(dir, "/")
	}
	if p == "" || p == "/" {
		p = key
	}
	keySelector[0] = p

	data := flagset.Arg(1)
	if data == "" {
		flagset.Usage()
		os.Exit(1)
	}
	backendStore, err := getBackendStore(backendName, endpoint)
	if err != nil {
		log.Fatal(err)
	}
	d, err := ioutil.ReadFile(data)
	if err != nil {
		log.Fatal(err)
	}

	log.Printf("setting consul node %q\n", nodeKey(key))
	if plaintext {
		err := setPlain(nodeKey(key), backendStore, d)
		if err != nil {
			log.Fatal(err)
			return
		}
		return
	}
	err = setEncrypted(nodeKey(key), keyring, d, backendStore, keySelector)
	if err != nil {
		log.Fatal(err)
	}
	return

}
Example #22
0
//  Hook up CmdHelpUsage and CmdHelpFoot with flag defaults to function flag.Usage.
func setupUsage(fs *flag.FlagSet) *flag.FlagSet {
	printNonEmpty := func(s string) {
		if s != "" {
			fmt.Fprintf(os.Stderr, "%s\n", s)
		}
	}
	fs.Usage = func() {
		printNonEmpty(CmdHelpUsage)
		fs.PrintDefaults()
		printNonEmpty(CmdHelpFoot)
	}
	return fs
}
Example #23
0
func ParseFlags(name string, pkg *deb.Package, fs *flag.FlagSet) error {
	err := fs.Parse(os.Args[1:])
	if err == nil {
		err = deb.ValidatePackage(pkg)
		if err != nil {
			println("")
			fmt.Fprintf(os.Stderr, "Usage of %s:\n", name)
			fs.PrintDefaults()
			println("")
		}
	}
	return err
}
Example #24
0
File: ssh.go Project: NetSys/quilt
// InstallFlags sets up parsing for command line flags.
func (sCmd *SSH) InstallFlags(flags *flag.FlagSet) {
	sCmd.common.InstallFlags(flags)

	flags.Usage = func() {
		fmt.Println("usage: quilt ssh [-H=<daemon_host>] <machine_num> " +
			"[ssh_options]")
		fmt.Println("`ssh` creates a SSH session to the specified machine. " +
			"The machine is identified the database ID produced by " +
			"`quilt queryMachines`.")
		fmt.Println("For example, to SSH to machine 5 with a specific " +
			"private key: quilt ssh 5 -i ~/.ssh/quilt")
		flags.PrintDefaults()
	}
}
Example #25
0
func register(name string, c cmd, fset *flag.FlagSet, about string) {
	if fset == nil {
		fset = flag.NewFlagSet("gosym "+name, flag.ExitOnError)
	}
	fset.Usage = func() {
		fmt.Fprint(os.Stderr, about)
		fset.PrintDefaults()
	}
	cmds = append(cmds, cmdEntry{
		name:  name,
		about: about,
		c:     c,
		fset:  fset,
	})
}
Example #26
0
File: stop.go Project: NetSys/quilt
// InstallFlags sets up parsing for command line flags.
func (sCmd *Stop) InstallFlags(flags *flag.FlagSet) {
	sCmd.common.InstallFlags(flags)

	flags.StringVar(&sCmd.namespace, "namespace", defaultNamespace,
		"the namespace to stop")

	flags.Usage = func() {
		fmt.Println("usage: quilt stop [-H=<daemon_host>] " +
			"[-namespace=<namespace>] <namespace>]")
		fmt.Println("`stop` creates an empty Stitch for the given namespace, " +
			"and sends it to the Quilt daemon to be executed.")
		fmt.Println("The result is that resources associated with the " +
			"namespace, such as VMs, are freed.")
		flags.PrintDefaults()
	}
}
Example #27
0
func PrintDefaults(flag *Flag.FlagSet) {
	var into bytes.Buffer
	flag.SetOutput(&into)
	flag.PrintDefaults()
	outfrom := bufio.NewReader(&into)
	for {
		line, err := outfrom.ReadString('\n')
		if err != nil {
			break
		}
		if strings.HasSuffix(line, ": \x00\n") {
			continue
		}
		fmt.Fprint(os.Stderr, line)
	}
}
Example #28
0
func Run(flag *flag.FlagSet) Command {
	query := crank.StartQuery{}
	flag.IntVar(&query.StopTimeout, "stop", -1, "Stop timeout in seconds")
	flag.IntVar(&query.StartTimeout, "start", -1, "Start timeout in seconds")
	flag.IntVar(&query.Pid, "pid", 0, "Only if the current pid matches")
	flag.BoolVar(&query.Wait, "wait", false, "Wait for a result")
	flag.StringVar(&query.Cwd, "cwd", "", "Working directory")

	flag.Usage = func() {
		fmt.Fprintf(os.Stderr, "Usage of %s run [opts] -- [command ...args]:\n", os.Args[0])
		flag.PrintDefaults()
	}

	return func(client *rpc.Client) (err error) {
		var reply crank.StartReply

		// Command and args are passed after
		if flag.NArg() > 0 {
			query.Command = flag.Args()
		}

		if err = client.Call("crank.Run", &query, &reply); err != nil {
			fmt.Println("Failed to start:", err)
			return
		}
		if reply.Code > 0 {
			fmt.Println("Exited with code:", reply.Code)
			return
		}

		fmt.Println("Started successfully")
		return
	}
}
Example #29
0
File: run.go Project: NetSys/quilt
// InstallFlags sets up parsing for command line flags.
func (rCmd *Run) InstallFlags(flags *flag.FlagSet) {
	rCmd.common.InstallFlags(flags)

	flags.StringVar(&rCmd.stitch, "stitch", "", "the stitch to run")
	flags.BoolVar(&rCmd.force, "f", false, "deploy without confirming changes")

	flags.Usage = func() {
		fmt.Println("usage: quilt run [-H=<daemon_host>] [-f] " +
			"[-stitch=<stitch>] <stitch>")
		fmt.Println("`run` compiles the provided stitch, and sends the " +
			"result to the Quilt daemon to be executed. Confirmation is " +
			"required if deploying the stitch would cause changes to an " +
			"existing cluster. Confirmation can be skipped with the " +
			"`-f` flag.")
		flags.PrintDefaults()
	}
}
Example #30
0
File: exec.go Project: NetSys/quilt
// InstallFlags sets up parsing for command line flags.
func (eCmd *Exec) InstallFlags(flags *flag.FlagSet) {
	eCmd.common.InstallFlags(flags)

	flags.StringVar(&eCmd.privateKey, "i", "",
		"the private key to use to connect to the host")
	flags.BoolVar(&eCmd.allocatePTY, "t", false,
		"attempt to allocate a pseudo-terminal")

	flags.Usage = func() {
		fmt.Println("usage: quilt exec [-H=<daemon_host>] [-i=<private_key>] " +
			"[-t] <stitch_id> <command>")
		fmt.Println("`exec` runs a command within the specified container. " +
			"The container is identified by the stitch ID produced by " +
			"`quilt containers`.")
		fmt.Println("For example, to get a shell in container 5 with a " +
			"specific private key: quilt exec -t -i ~/.ssh/quilt 5 sh")
		flags.PrintDefaults()
	}
}