File tree Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Expand file tree Collapse file tree 1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -17,12 +17,14 @@ import (
17
17
"fmt"
18
18
"log"
19
19
"os"
20
+ "path/filepath"
21
+ "strings"
20
22
21
23
"github.com/cli/browser"
22
24
)
23
25
24
26
func usage () {
25
- fmt .Fprintf (os .Stderr , "Usage:\n %s [ file] \n " , os .Args [0 ])
27
+ fmt .Fprintf (os .Stderr , "Usage:\n %s {<url> | < file> | -} \n " , filepath . Base ( os .Args [0 ]) )
26
28
flag .PrintDefaults ()
27
29
}
28
30
@@ -39,12 +41,21 @@ func check(err error) {
39
41
40
42
func main () {
41
43
args := flag .Args ()
42
- switch len (args ) {
43
- case 0 :
44
- check (browser .OpenReader (os .Stdin ))
45
- case 1 :
46
- check (browser .OpenFile (args [0 ]))
47
- default :
44
+
45
+ if len (args ) != 1 {
48
46
usage ()
47
+ os .Exit (1 )
48
+ }
49
+
50
+ if args [0 ] == "-" {
51
+ check (browser .OpenReader (os .Stdin ))
52
+ return
53
+ }
54
+
55
+ if strings .HasPrefix (args [0 ], "http:" ) || strings .HasPrefix (args [0 ], "https:" ) {
56
+ check (browser .OpenURL (args [0 ]))
57
+ return
49
58
}
59
+
60
+ check (browser .OpenFile (args [0 ]))
50
61
}
You can’t perform that action at this time.
0 commit comments