Fix global --repo, --current-branch functionality

Turns out I've tried to use the flags' value too early: they are not yet
parsed out at package `init()` time.
This commit is contained in:
Mislav Marohnić 2019-10-18 19:24:16 +02:00
parent e2767b463c
commit c82e38353f

View file

@ -17,7 +17,9 @@ var (
func init() {
RootCmd.PersistentFlags().StringVarP(&currentRepo, "repo", "R", "", "current GitHub repository")
RootCmd.PersistentFlags().StringVarP(&currentBranch, "current-branch", "B", "", "current git branch")
}
func initContext() {
ctx := context.InitDefaultContext()
ctx.SetBranch(currentBranch)
repo := currentRepo
@ -35,6 +37,9 @@ var RootCmd = &cobra.Command{
Short: "GitHub CLI",
Long: `Do things with GitHub from your terminal`,
Args: cobra.MinimumNArgs(1),
PersistentPreRun: func(cmd *cobra.Command, args []string) {
initContext()
},
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("root")
},