Esempio n. 1
0
func (r *Runner) Execute() ExecError {
	args := NewArgs(r.Args)
	if args.Command == "" {
		printUsage()
		return newExecError(nil)
	}

	expandAlias(args)
	slurpGlobalFlags(args)

	for _, cmd := range All() {
		if cmd.Name() == args.Command && cmd.Runnable() {
			if !cmd.GitExtension {
				cmd.Flag.Usage = func() {
					cmd.PrintUsage()
				}
				if err := cmd.Flag.Parse(args.Params); err != nil {
					if err == flag.ErrHelp {
						return newExecError(nil)
					} else {
						return newExecError(err)
					}
				}

				args.Params = cmd.Flag.Args()
			}

			cmd.Run(cmd, args)

			cmds := args.Commands()
			var err error
			if args.Noop {
				printCommands(cmds)
			} else {
				err = executeCommands(cmds)
			}

			return newExecError(err)
		}
	}

	err := git.Spawn(args.Command, args.Params...)
	return newExecError(err)
}
Esempio n. 2
0
func (r *Runner) Execute() error {
	args := NewArgs(r.Args)
	if args.Command == "" {
		usage()
	}

	expandAlias(args)
	slurpGlobalFlags(args)

	for _, cmd := range All() {
		if cmd.Name() == args.Command && cmd.Runnable() {
			if !cmd.GitExtension {
				cmd.Flag.Usage = func() {
					cmd.PrintUsage()
				}
				if err := cmd.Flag.Parse(args.Params); err != nil {
					return err
				}

				args.Params = cmd.Flag.Args()
			}

			cmd.Run(cmd, args)

			cmds := args.Commands()
			if args.Noop {
				printCommands(cmds)
			} else {
				err := executeCommands(cmds)
				if err != nil {
					return err
				}
			}

			return nil
		}
	}

	return git.SysExec(args.Command, args.Params...)
}