Example #1
0
func TestMainHelp(t *testing.T) {
	t.Parallel()
	a := subcommandstest.MakeAppMock(t, application)
	args := []string{"help"}
	r := subcommands.Run(a, args)
	ut.AssertEqual(t, 0, r)
	a.CheckBuffer(true, false)
}
Example #2
0
func RunApplication() {
	//defer FlushLog()
	mgollective := &subcommands.DefaultApplication{
		Name:     "mgo",
		Title:    "mgollective",
		Commands: append(commands, subcommands.CmdHelp),
	}
	subcommands.Run(mgollective, os.Args[1:])
}
Example #3
0
func TestSleep(t *testing.T) {
	defer mockStdout(t)()

	// If running with "go test -v", the following log entry will be printed:
	// utiltest.go:132: 2010/01/02 03:04:05 Simulating sleeping for 1s.
	out := ut.NewWriter(t)
	defer out.Close()
	log.SetOutput(out)
	ut.AssertEqual(t, 0, subcommands.Run(application, []string{"sleep", "-duration", "1"}))
	assertStdout(t, "")
}
Example #4
0
func main() {
	opts := auth.Options{Logger: gologger.Get()}
	application := &subcommands.DefaultApplication{
		Name:  "auth",
		Title: "Chrome Infra Authentication tool",
		Commands: []*subcommands.Command{
			subcommands.CmdHelp,
			authcli.SubcommandInfo(opts, "info"),
			authcli.SubcommandLogin(opts, "login"),
			authcli.SubcommandLogout(opts, "logout"),
		},
	}
	os.Exit(subcommands.Run(application, nil))
}
func TestBadCommand(t *testing.T) {
	app := &subcommands.DefaultApplication{
		Name:  "name",
		Title: "doc",
		Commands: []*subcommands.Command{
			subcommands.CmdHelp,
		},
	}
	a := MakeAppMock(t, app)
	args := []string{"non_existing_command"}
	r := subcommands.Run(a, args)
	ut.AssertEqual(t, r, 2)
	a.CheckBuffer(false, true)
}
func TestHelp(t *testing.T) {
	app := &subcommands.DefaultApplication{
		Name:  "name",
		Title: "doc",
		Commands: []*subcommands.Command{
			subcommands.CmdHelp,
		},
	}
	a := MakeAppMock(t, app)
	args := []string{"help"}
	r := subcommands.Run(a, args)
	ut.AssertEqual(t, r, 0)
	a.CheckBuffer(true, false)
}
Example #7
0
func main() {
	log.SetFlags(log.Lmicroseconds)
	os.Exit(subcommands.Run(application, nil))
}
Example #8
0
func TestGreet(t *testing.T) {
	defer mockStdout(t)()

	ut.AssertEqual(t, 0, subcommands.Run(application, []string{"greet", "active tester"}))
	assertStdout(t, "Hi active tester!\n")
}
Example #9
0
func main() {
	log.SetFlags(log.Lmicroseconds)
	d := &dumbapp{application, log.New(application.GetErr(), "", log.LstdFlags|log.Lmicroseconds)}
	os.Exit(subcommands.Run(d, nil))
}
Example #10
0
func main() {
	os.Exit(subcommands.Run(application, nil))
}
Example #11
0
func main() {
	os.Exit(subcommands.Run(application, os.Args[1:]))
}
Example #12
0
func main() {
	os.Exit(subcommands.Run(application, fixFlagsPosition(os.Args[1:])))
}
Example #13
0
func main() {
	subcommands.KillStdLog()
	s := &sample{application, log.New(ioutil.Discard, "", log.LstdFlags|log.Lmicroseconds)}
	os.Exit(subcommands.Run(s, nil))
}
Example #14
0
func (a *DumbcasAppMock) Run(args []string, expected int) {
	a.GetLog().Printf("%s", args)
	returncode := subcommands.Run(a, args)
	ut.AssertEqual(a, expected, returncode)
}
Example #15
0
func (c *askRun) Run(a subcommands.Application, args []string, env subcommands.Env) int {
	d := a.(SampleApplication)
	// Create an inner application.
	return subcommands.Run(askApplication{d}, args)
}