diff --git a/command/issue.go b/command/issue.go index daf974e2c..1cd25941c 100644 --- a/command/issue.go +++ b/command/issue.go @@ -22,6 +22,8 @@ import ( ) func init() { + issueCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` format") + RootCmd.AddCommand(issueCmd) issueCmd.AddCommand(issueStatusCmd) diff --git a/command/pr.go b/command/pr.go index d1720ca42..79c65b874 100644 --- a/command/pr.go +++ b/command/pr.go @@ -23,6 +23,8 @@ import ( ) func init() { + prCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` format") + RootCmd.AddCommand(prCmd) prCmd.AddCommand(prCheckoutCmd) prCmd.AddCommand(prCreateCmd) diff --git a/command/root.go b/command/root.go index 693603e05..cf0e3cbb1 100644 --- a/command/root.go +++ b/command/root.go @@ -52,7 +52,6 @@ func init() { RootCmd.AddCommand(versionCmd) RootCmd.SetVersionTemplate(versionOutput) - RootCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` format") RootCmd.PersistentFlags().Bool("help", false, "Show help for command") RootCmd.Flags().Bool("version", false, "Show gh version") // TODO: @@ -304,8 +303,8 @@ func changelogURL(version string) string { } func determineBaseRepo(apiClient *api.Client, cmd *cobra.Command, ctx context.Context) (ghrepo.Interface, error) { - repo, err := cmd.Flags().GetString("repo") - if err == nil && repo != "" { + repo, _ := cmd.Flags().GetString("repo") + if repo != "" { baseRepo, err := ghrepo.FromFullName(repo) if err != nil { return nil, fmt.Errorf("argument error: %w", err) @@ -313,17 +312,12 @@ func determineBaseRepo(apiClient *api.Client, cmd *cobra.Command, ctx context.Co return baseRepo, nil } - baseOverride, err := cmd.Flags().GetString("repo") - if err != nil { - return nil, err - } - remotes, err := ctx.Remotes() if err != nil { return nil, err } - repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, baseOverride) + repoContext, err := context.ResolveRemotesToRepos(remotes, apiClient, "") if err != nil { return nil, err }