Beispiel #1
0
func main() {
	if len(os.Args) < 2 {
		showHelp()
		os.Exit(1)
	}
	if !someutils.Exists(os.Args[1]) {
		showHelp()
		os.Exit(1)
	}
	err := someutils.Call(os.Args[1], os.Args[1:])
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		os.Exit(1)
	}
}
Beispiel #2
0
func main() {
	some.Init() //ensure the utils are registered.
	if len(os.Args) < 2 {
		showHelp(" No command specified.")
		os.Exit(1)
	}
	if !someutils.Exists(os.Args[1]) {
		showHelp(" Command does not exist.")
		os.Exit(1)
	}
	err, code := someutils.Call(os.Args[1], os.Args[1:])
	if err != nil {
		if code != 0 {
			fmt.Fprintf(os.Stderr, "Error: %v\n", err)
			os.Exit(code)
		}
	}
}
Beispiel #3
0
// ParseFlags parses flags from a commandline []string
func (xargs *SomeXargs) ParseFlags(call []string, errPipe io.Writer) (error, int) {
	flagSet := uggo.NewFlagSetDefault("xargs", "[options] [args...]", someutils.VERSION)
	flagSet.SetOutput(errPipe)
	// TODO multiple processes at once ?
	flagSet.AliasedIntVar(&xargs.maxProcesses, []string{"P", "max-procs"}, 1, "Maximum processes")
	err, code := flagSet.ParsePlus(call[1:])
	if err != nil {
		return err, code
	}

	args := flagSet.Args()
	if len(args) < 1 {
		return errors.New("No command specified"), 1
	}
	if !someutils.Exists(args[0]) {
		return errors.New("Command does not exist."), 1
	}
	xargs.utilFactory = someutils.GetCliPipableFactory(args[0])
	xargs.utilArgs = args
	return nil, 0
}