Skip to content

Commit ef6a01f

Browse files
committed
Fix argument parse error
e.g. '-H "Authorization: Bearer xxxx"'
1 parent e5e6539 commit ef6a01f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

main.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"os/exec"
1010
"runtime"
1111
"strings"
12+
13+
"gopkg.in/alessio/shellescape.v1"
1214
)
1315

1416
const (
@@ -70,12 +72,7 @@ func newCLI(args []string) CLI {
7072
case "--edit", "--edit-config":
7173
c.opt.edit = true
7274
default:
73-
u, err := url.ParseRequestURI(arg)
74-
if err == nil {
75-
c.urls = append(c.urls, *u)
76-
} else {
77-
c.args = append(c.args, arg)
78-
}
75+
c.args = append(c.args, arg)
7976
}
8077
}
8178

@@ -116,6 +113,16 @@ func (c CLI) run() int {
116113
return c.exit(c.cfg.Edit())
117114
}
118115

116+
if len(c.args) == 0 {
117+
return c.exit(errors.New("too few arguments"))
118+
}
119+
u, err := url.ParseRequestURI(c.args[len(c.args)-1])
120+
if err != nil {
121+
return c.exit(err)
122+
}
123+
c.urls = append(c.urls, *u)
124+
c.args = c.args[:len(c.args)-1]
125+
119126
url := c.getURL()
120127
if url == "" {
121128
return c.exit(errors.New("invalid url or url not given"))
@@ -142,7 +149,7 @@ func (c CLI) run() int {
142149
})
143150
}
144151

145-
authHeader := fmt.Sprintf("'Authorization: Bearer %s'", token)
152+
authHeader := fmt.Sprintf("Authorization: Bearer %s", token)
146153
args := append(
147154
[]string{"-H", authHeader}, // For IAP
148155
c.args...,
@@ -190,7 +197,7 @@ func (s shell) run() error {
190197
return err
191198
}
192199
for _, arg := range s.args {
193-
command += " " + arg
200+
command += " " + shellescape.Quote(arg)
194201
}
195202
var cmd *exec.Cmd
196203
if runtime.GOOS == "windows" {

0 commit comments

Comments
 (0)