Add the release view --web flag

This commit is contained in:
Mislav Marohnić 2020-09-09 17:01:29 +02:00
parent ad0bbde351
commit 3d58fa785f
2 changed files with 22 additions and 0 deletions

View file

@ -22,6 +22,7 @@ type ViewOptions struct {
BaseRepo func() (ghrepo.Interface, error)
TagName string
WebMode bool
}
func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Command {
@ -55,6 +56,8 @@ func NewCmdView(f *cmdutil.Factory, runF func(*ViewOptions) error) *cobra.Comman
},
}
cmd.Flags().BoolVarP(&opts.WebMode, "web", "w", false, "Open the release in the browser")
return cmd
}
@ -83,6 +86,13 @@ func viewRun(opts *ViewOptions) error {
}
}
if opts.WebMode {
if opts.IO.IsStdoutTTY() {
fmt.Fprintf(opts.IO.ErrOut, "Opening %s in your browser.\n", utils.DisplayURL(release.HTMLURL))
}
return utils.OpenInBrowser(release.HTMLURL)
}
if opts.IO.IsStdoutTTY() {
if err := renderReleaseTTY(opts.IO, release); err != nil {
return err

View file

@ -32,6 +32,7 @@ func Test_NewCmdView(t *testing.T) {
isTTY: true,
want: ViewOptions{
TagName: "v1.2.3",
WebMode: false,
},
},
{
@ -40,6 +41,16 @@ func Test_NewCmdView(t *testing.T) {
isTTY: true,
want: ViewOptions{
TagName: "",
WebMode: false,
},
},
{
name: "web mode",
args: "-w",
isTTY: true,
want: ViewOptions{
TagName: "",
WebMode: true,
},
},
}
@ -78,6 +89,7 @@ func Test_NewCmdView(t *testing.T) {
}
assert.Equal(t, tt.want.TagName, opts.TagName)
assert.Equal(t, tt.want.WebMode, opts.WebMode)
})
}
}