Example #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)
}
Example #2
0
func (r *Runner) Execute() ExecError {
	args := NewArgs(os.Args[1:])

	if args.Command == "" {
		printUsage()
		return newExecError(nil)
	}

	updater := NewUpdater()
	err := updater.PromptForUpdate()
	utils.Check(err)

	expandAlias(args)
	slurpGlobalFlags(args)

	cmd := r.Lookup(args.Command)
	if cmd != nil && cmd.Runnable() {
		return r.Call(cmd, args)
	}

	err = git.Spawn(args.Command, args.Params...)
	return newExecError(err)
}