Skip to content

Commit

Permalink
Fix argument parse error
Browse files Browse the repository at this point in the history
e.g. '-H "Authorization: Bearer xxxx"'
babarot committed Jan 25, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e5e6539 commit ef6a01f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import (
"os/exec"
"runtime"
"strings"

"gopkg.in/alessio/shellescape.v1"
)

const (
@@ -70,12 +72,7 @@ func newCLI(args []string) CLI {
case "--edit", "--edit-config":
c.opt.edit = true
default:
u, err := url.ParseRequestURI(arg)
if err == nil {
c.urls = append(c.urls, *u)
} else {
c.args = append(c.args, arg)
}
c.args = append(c.args, arg)
}
}

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

if len(c.args) == 0 {
return c.exit(errors.New("too few arguments"))
}
u, err := url.ParseRequestURI(c.args[len(c.args)-1])
if err != nil {
return c.exit(err)
}
c.urls = append(c.urls, *u)
c.args = c.args[:len(c.args)-1]

url := c.getURL()
if url == "" {
return c.exit(errors.New("invalid url or url not given"))
@@ -142,7 +149,7 @@ func (c CLI) run() int {
})
}

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

0 comments on commit ef6a01f

Please sign in to comment.