Beispiel #1
0
	"bazil.org/bazil/cliutil/subcommands"
)

type sum struct {
	subcommands.Description
	flag.FlagSet
	Arguments struct {
		A int
		B int
	}
	Config struct {
		Frob bool
	}
}

func (a *sum) Run() int {
	return int(a.Arguments.A + a.Arguments.B)
}

// Calc is exported so the unit tests can inspect it.
var Sum = sum{
	Description: "sum two numbers",
}

var _ = subcommands.FlagParser(&Sum)

func init() {
	subcommands.Register(&Sum)
	Sum.BoolVar(&Sum.Config.Frob, "frobnicate", false, "frobnicate the qubbitz")
}
Beispiel #2
0
package calc

import (
	"flag"

	"bazil.org/bazil/cliutil/subcommands"
)

type calc struct {
	flag.FlagSet
	Config struct {
		Verbose bool
	}
}

// Calc is exported so the unit tests can inspect it.
var Calc calc

var _ = subcommands.FlagParser(&Calc)

func init() {
	Calc.BoolVar(&Calc.Config.Verbose, "v", false, "verbose output")
	subcommands.Register(&Calc)
}