simplified the if block for flags, now allows for checking destination before opening browser
This commit is contained in:
parent
88e2a9f748
commit
fdca340b28
1 changed files with 6 additions and 7 deletions
|
|
@ -86,21 +86,16 @@ func openInBrowser(cmd *cobra.Command, opts *BrowseOptions) {
|
|||
repoUrl := ghrepo.GenerateRepoURL(baseRepo, "")
|
||||
parseArgs(opts)
|
||||
|
||||
if opts.SelectorArg == "" {
|
||||
if !hasArgs(opts) { // handle flags without args
|
||||
if opts.ProjectsFlag {
|
||||
repoUrl += "/projects"
|
||||
printExit(exitSuccess, cmd, opts, repoUrl)
|
||||
} else if opts.SettingsFlag {
|
||||
repoUrl += "/settings"
|
||||
printExit(exitSuccess, cmd, opts, repoUrl)
|
||||
} else if opts.WikiFlag {
|
||||
repoUrl += "/wiki"
|
||||
printExit(exitSuccess, cmd, opts, repoUrl)
|
||||
} else if getFlagAmount(cmd) == 0 {
|
||||
printExit(exitSuccess, cmd, opts, repoUrl)
|
||||
}
|
||||
|
||||
opts.Browser.Browse(repoUrl)
|
||||
printExit(exitSuccess, cmd, opts, repoUrl)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +139,10 @@ func printExit(errorCode exitCode, cmd *cobra.Command, opts *BrowseOptions, url
|
|||
|
||||
}
|
||||
|
||||
func hasArgs(opts *BrowseOptions) bool {
|
||||
return opts.SelectorArg != ""
|
||||
}
|
||||
|
||||
func getFlagAmount(cmd *cobra.Command) int {
|
||||
return cmd.Flags().NFlag()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue