Example #1
0
func run(sleep time.Duration, path string, command string, args ...string) {
	fmt.Println("[Installer] Running: ", command, args)
	cmd := executil.Command(command, args...)
	cmd.OutputPrefix = command
	err := cmd.StartAndWait()
	if err != nil {
		fmt.Println(err)
	}

	if sleep != 0 {
		fmt.Printf("[Installer] Sleeping: %s for %f seconds \n", command, sleep.Seconds())
		time.Sleep(sleep)
	}
}
Example #2
0
func main() {
	// Check for our command line configuration flags
	var (
		versionUsage = "Prints current version" + " (v. " + Version + ")"
		versionPtr   = flag.Bool("version", false, versionUsage)
	)

	// Set up short hand flags
	flag.BoolVar(versionPtr, "v", false, versionUsage+" (shorthand)")
	flag.Parse()

	if *versionPtr {
		fmt.Println(Version)
		os.Exit(0)
	}

	// usage description
	usage := "protogen /path/to/myService.proto"
	options := "--version (-v)"
	optionsDesc := versionUsage

	// Create help message with usage messaging
	helpMessage := fmt.Sprintf(bold("USAGE:")+"\n%s%v", space, usage)
	// Break between messages
	helpMessage += br
	// Add options messaging
	helpMessage += fmt.Sprintf(bold("OPTIONS:")+"\n%v\n%s%v", options, space, optionsDesc)

	// Check arg for appname to load
	if len(os.Args) != 2 {
		fmt.Println(helpMessage)
		os.Exit(0)
	}

	protoPath := os.Args[1]

	// run protoc command (protoc --go_out=plugins=grpc:. $proto)
	cmd := executil.Command("protoc", "--go_out=plugins=grpc:.", protoPath)
	cmd.OutputPrefix = "protoc"
	err := cmd.StartAndWait()
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Println(bold("SUCCESS: ") + protoPath + " pb.go successfully created.")

}