diff --git a/command/issue.go b/command/issue.go index 2b85efc75..069b78e5b 100644 --- a/command/issue.go +++ b/command/issue.go @@ -85,7 +85,8 @@ func issueList(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + baseRepo, err := determineBaseRepo(cmd, ctx, repo) if err != nil { return err } @@ -165,7 +166,8 @@ func issueStatus(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + baseRepo, err := determineBaseRepo(cmd, ctx, repo) if err != nil { return err } @@ -222,7 +224,8 @@ func issueView(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + baseRepo, err := determineBaseRepo(cmd, ctx, repo) if err != nil { return err } @@ -294,8 +297,9 @@ func issueFromArg(apiClient *api.Client, baseRepo ghrepo.Interface, arg string) func issueCreate(cmd *cobra.Command, args []string) error { ctx := contextForCommand(cmd) + repoOverride, _ := cmd.Flags().GetString("repo") // NB no auto forking like over in pr create - baseRepo, err := determineBaseRepo(cmd, ctx) + baseRepo, err := determineBaseRepo(cmd, ctx, repoOverride) if err != nil { return err } diff --git a/command/pr.go b/command/pr.go index e1c8e796b..2cef559e6 100644 --- a/command/pr.go +++ b/command/pr.go @@ -76,7 +76,8 @@ func prStatus(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + baseRepo, err := determineBaseRepo(cmd, ctx, repo) if err != nil { return err } @@ -132,7 +133,8 @@ func prList(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + baseRepo, err := determineBaseRepo(cmd, ctx, repo) if err != nil { return err } @@ -257,7 +259,8 @@ func prView(cmd *cobra.Command, args []string) error { return err } - baseRepo, err := determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + baseRepo, err := determineBaseRepo(cmd, ctx, repo) if err != nil { return err } diff --git a/command/repo.go b/command/repo.go index 1dc9b13a5..4b95fd511 100644 --- a/command/repo.go +++ b/command/repo.go @@ -265,7 +265,8 @@ func repoFork(cmd *cobra.Command, args []string) error { var toFork ghrepo.Interface inParent := false // whether or not we're forking the repo we're currently "in" if len(args) == 0 { - baseRepo, err := determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + baseRepo, err := determineBaseRepo(cmd, ctx, repo) if err != nil { return fmt.Errorf("unable to determine base repository: %w", err) } @@ -389,7 +390,8 @@ func repoView(cmd *cobra.Command, args []string) error { var toView ghrepo.Interface if len(args) == 0 { var err error - toView, err = determineBaseRepo(cmd, ctx) + repo, _ := cmd.Flags().GetString("repo") + toView, err = determineBaseRepo(cmd, ctx, repo) if err != nil { return err } diff --git a/command/root.go b/command/root.go index cae4bab4e..8a1a37335 100644 --- a/command/root.go +++ b/command/root.go @@ -173,7 +173,11 @@ func changelogURL(version string) string { return url } -func determineBaseRepo(cmd *cobra.Command, ctx context.Context) (ghrepo.Interface, error) { +func determineBaseRepo(cmd *cobra.Command, ctx context.Context, repo string) (ghrepo.Interface, error) { + if repo != "" { + return ghrepo.FromFullName(repo), nil + } + apiClient, err := apiClientForContext(ctx) if err != nil { return nil, err