Don't list remotes when --repo flag is set

This commit is contained in:
Dmitry Sharshakov 2020-03-14 23:14:38 +03:00
parent 58f6bef8a7
commit 45c2a16d49
4 changed files with 23 additions and 10 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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