Beispiel #1
0
func main() {
	app := stdcli.New()
	app.Version = Version
	app.Usage = "command-line application management"
	err := app.Run(os.Args)
	if err != nil {
		os.Exit(1)
	}
}
Beispiel #2
0
func appRun(args []string) (string, string) {
	app := stdcli.New()
	stdcli.Exiter = func(code int) {}
	stdcli.Runner = func(bin string, args ...string) error { return nil }
	stdcli.Querier = func(bin string, args ...string) ([]byte, error) { return []byte{}, nil }
	stdcli.Tagger = func() string { return "1435444444" }
	stdcli.Writer = func(filename string, data []byte, perm os.FileMode) error { return nil }

	// Capture stdout and stderr to strings via Pipes
	oldErr := os.Stderr
	oldOut := os.Stdout

	er, ew, _ := os.Pipe()
	or, ow, _ := os.Pipe()

	os.Stderr = ew
	os.Stdout = ow

	errC := make(chan string)
	// copy the output in a separate goroutine so printing can't block indefinitely
	go func() {
		var buf bytes.Buffer
		io.Copy(&buf, er)
		errC <- buf.String()
	}()

	outC := make(chan string)
	// copy the output in a separate goroutine so printing can't block indefinitely
	go func() {
		var buf bytes.Buffer
		io.Copy(&buf, or)
		outC <- buf.String()
	}()

	_ = app.Run(args)

	// restore stderr, stdout
	ew.Close()
	os.Stderr = oldErr
	err := <-errC

	ow.Close()
	os.Stdout = oldOut
	out := <-outC

	return out, err
}
Beispiel #3
0
func main() {
	app := stdcli.New()
	app.Version = Version
	app.Usage = "command-line application management"
	app.Run(os.Args)
}