// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
Execute adds all child commands to the root command and sets flags appropriately.
This is called by main.main(). It only needs to happen once to the rootCmd.
// Execute adds all child commands to the root command and sets flags appropriately . // This is called by main . main () . It only needs to happen once to the rootCmd .
func Execute() {
	_, err := gitconfig.Local("remote.upstream.url")
	if err == nil {
		forkedFromRemote = "upstream"
	}
	ur, err := git.UpstreamRemote()
	if err == nil {
		forkedFromRemote = ur
	}
	if forkedFromRemote == "" {
		masterRemote, err := gitconfig.Local("branch.master.remote")
		if err == nil {
			forkedFromRemote = masterRemote
		}
	}
	if forkedFromRemote == "origin" {
		_, err = gitconfig.Local("remote." + lab.User() + ".url")
		if err == nil {
			forkRemote = lab.User()
		}
	}
	cmd, _, err := RootCmd.Find(os.Args[1:])
	if err != nil || cmd.Use == "clone" {
		if (cmd.Use == "clone" && len(os.Args) > 2) || os.Args[1] == "help" {
			err = cmd.ParseFlags(os.Args[1:])
			if err == nil {
				if err := RootCmd.Execute(); err != nil {
					os.Exit(1)
				}
				return
			}
		}
		if os.Args[1] == "create" {
			log.Fatalf("Please call `hub create` directly for github, the lab equivalent is `lab project create`")
		}
		if os.Args[1] == "browse" {
			log.Fatalf("Please call `hub browse` directly for github, the lab equivalent is `lab <object> browse`")
		}
		if os.Args[1] == "alias" {
			log.Fatalf("Please call `hub alias` directly for github, there is no lab equivalent`")
		}
		err = git.New(os.Args[1:]...).Run()
		if exiterr, ok := err.(*exec.ExitError); ok {
			if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
				os.Exit(status.ExitStatus())
			}
		}
		if err != nil {
			log.Fatal(err)
		}
		return
	}
	if cmd.Use == RootCmd.Use && len(os.Args) > 1 {
		var hFlaged bool
		for _, v := range os.Args {
			if v == "--help" {
				hFlaged = true
			}
		}
		if !hFlaged {
			git.New(os.Args[1:]...).Run()
			return
		}
	}
	if err := RootCmd.Execute(); err != nil {
		os.Exit(1)
	}
}
func Execute ( ) { _ , err := gitconfig . Local ( " " ) if err == nil { forkedFromRemote = " " } ur , err := git . UpstreamRemote ( ) if err == nil { forkedFromRemote = ur } if forkedFromRemote == " " { masterRemote , err := gitconfig . Local ( " " ) if err == nil { forkedFromRemote = masterRemote } } if forkedFromRemote == " " { _ , err = gitconfig . Local ( " " + lab . User ( ) + " " ) if err == nil { forkRemote = lab . User ( ) } } cmd , _ , err := RootCmd . Find ( os . Args [ 1 : ] ) if err != nil || cmd . Use == " " { if ( cmd . Use == " " && len ( os . Args ) > 2 ) || os . Args [ 1 ] == " " { err = cmd . ParseFlags ( os . Args [ 1 : ] ) if err == nil { if err := RootCmd . Execute ( ) ; err != nil { os . Exit ( 1 ) } return } } if os . Args [ 1 ] == " " { log . Fatalf ( " " ) } if os . Args [ 1 ] == " " { log . Fatalf ( " " ) } if os . Args [ 1 ] == " " { log . Fatalf ( " " ) } err = git . New ( os . Args [ 1 : ] ... ) . Run ( ) if exiterr , ok := err . ( * exec . ExitError ) ; ok { if status , ok := exiterr . Sys ( ) . ( syscall . WaitStatus ) ; ok { os . Exit ( status . ExitStatus ( ) ) } } if err != nil { log . Fatal ( err ) } return } if cmd . Use == RootCmd . Use && len ( os . Args ) > 1 { var hFlaged bool for _ , v := range os . Args { if v == " " { hFlaged = true } } if ! hFlaged { git . New ( os . Args [ 1 : ] ... ) . Run ( ) return } } if err := RootCmd . Execute ( ) ; err != nil { os . Exit ( 1 ) } }
Execute adds all child commands to the root command and sets flags appropriately.
Execute adds all child commands to the root command and sets flags appropriately .
// use the remote tracked by the branch if set // Check if the user fork exists // Check if the user is calling a lab command or if we should passthrough // NOTE: The help command won't be found by Find, which we are counting on // Determine if any undefined flags were passed to "clone" // TODO: Evaluate and support some of these flags // NOTE: `hub help -a` wraps the `git help -a` output // ParseFlags will err in these cases // Execute has already logged the error // Lab passthrough for these commands can cause confusion. See #163 // Passthrough to git for any unrecognized commands // allow flags to the root cmd to be passed through. Technically we'll drop any exit code info which isn't ideal. // TODO: remove for 1.0 when we stop wrapping git // Execute has already logged the error