Fix repo override
This commit is contained in:
parent
8dd1e12f64
commit
8ff42bf28c
2 changed files with 19 additions and 6 deletions
|
|
@ -169,12 +169,6 @@ func mainRun() exitCode {
|
|||
return authError
|
||||
}
|
||||
|
||||
// enable `--repo` override
|
||||
if cmd.Flags().Lookup("repo") != nil {
|
||||
repoOverride, _ := cmd.Flags().GetString("repo")
|
||||
cmdFactory.BaseRepo = cmdutil.OverrideBaseRepoFunc(cmdFactory, repoOverride)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,8 +7,27 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func executeParentHooks(cmd *cobra.Command, args []string) error {
|
||||
for cmd.HasParent() {
|
||||
cmd = cmd.Parent()
|
||||
if cmd.PersistentPreRunE != nil {
|
||||
return cmd.PersistentPreRunE(cmd, args)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func EnableRepoOverride(cmd *cobra.Command, f *Factory) {
|
||||
cmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `[HOST/]OWNER/REPO` format")
|
||||
|
||||
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
|
||||
if err := executeParentHooks(cmd, args); err != nil {
|
||||
return err
|
||||
}
|
||||
repoOverride, _ := cmd.Flags().GetString("repo")
|
||||
f.BaseRepo = OverrideBaseRepoFunc(f, repoOverride)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func OverrideBaseRepoFunc(f *Factory, override string) func() (ghrepo.Interface, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue