Skip to content

Commit

Permalink
Fix for #100 : Stop -- parameter being passed literally to command (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ocean authored Aug 5, 2022
1 parent 8ae52e3 commit 4827ba1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
10 changes: 7 additions & 3 deletions ahoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,11 @@ func getCommands(config Config) []cli.Command {

// c.Args() is not a slice apparently.
for _, arg := range c.Args() {
cmdArgs = append(cmdArgs, arg)
if arg != "--" {
cmdArgs = append(cmdArgs, arg)
}
}
// fmt.Printf("%s : %+v\n", "Args", cmdArgs)

// Replace the entry point placeholders.
cmdEntrypoint = config.Entrypoint[:]
Expand Down Expand Up @@ -254,7 +257,7 @@ func getCommands(config Config) []cli.Command {
newCmd.Subcommands = subCommands
}

//log.Println("found command: ", name, " > ", cmd.Cmd )
// log.Println("found command: ", name, " > ", cmd.Cmd)
exportCmds = append(exportCmds, newCmd)
}

Expand Down Expand Up @@ -378,6 +381,7 @@ func NoArgsAction(c *cli.Context) {
// BeforeCommand runs before every command so arguments or flags must be passed
func BeforeCommand(c *cli.Context) error {
args := c.Args()
// fmt.Printf("%+v\n", args)
if c.Bool("version") {
fmt.Println(version)
return errors.New("don't continue with commands")
Expand All @@ -390,7 +394,7 @@ func BeforeCommand(c *cli.Context) error {
}
return errors.New("don't continue with commands")
}
//fmt.Printf("%+v\n", args)
// fmt.Printf("%+v\n", args)
return nil
}

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ go 1.16

require (
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/fzipp/gocyclo v0.5.1 // indirect
github.com/urfave/cli v1.22.9
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0
)
16 changes: 0 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/fzipp/gocyclo v0.5.1 h1:L66amyuYogbxl0j2U+vGqJXusPF2IkduvXLnYD5TFgw=
github.com/fzipp/gocyclo v0.5.1/go.mod h1:rXPyn8fnlpa0R2csP/31uerbiVBugk5whMdlyaLkLoA=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand All @@ -16,20 +14,6 @@ github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQD
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw=
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug=
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
6 changes: 6 additions & 0 deletions testdata/simple.ahoy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,9 @@ ahoyapi: v2
commands:
echo:
cmd: echo "$@"

list:
cmd: ls -a "$@"

whalesay:
cmd: docker run --rm docker/whalesay cowsay -f dragon "$@"
5 changes: 5 additions & 0 deletions tests/simple.bats
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@
result="$(./ahoy -f testdata/simple.ahoy.yml echo something)"
[ "$result" == "something" ]
}

@test "run a simple ahoy command (ls -a) with an extra parameter (-l)" {
run ./ahoy -f testdata/simple.ahoy.yml list -- -l
[ "${#lines[@]}" -gt 13 ]
}

0 comments on commit 4827ba1

Please sign in to comment.