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:
parent
e2767b463c
commit
c82e38353f
1 changed files with 5 additions and 0 deletions
|
|
@ -17,7 +17,9 @@ var (
|
|||
func init() {
|
||||
RootCmd.PersistentFlags().StringVarP(¤tRepo, "repo", "R", "", "current GitHub repository")
|
||||
RootCmd.PersistentFlags().StringVarP(¤tBranch, "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")
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue