|
|
@ -1,18 +1,19 @@
|
|
|
|
package cli
|
|
|
|
package cli
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Command struct {
|
|
|
|
type Command struct {
|
|
|
|
Name string
|
|
|
|
Name string
|
|
|
|
ShortName string
|
|
|
|
ShortName string
|
|
|
|
Usage string
|
|
|
|
Usage string
|
|
|
|
Description string
|
|
|
|
Description string
|
|
|
|
Action func(context *Context)
|
|
|
|
Action func (context *Context)
|
|
|
|
Flags []Flag
|
|
|
|
Flags []Flag
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c Command) Run(ctx *Context) {
|
|
|
|
func (c Command) Run(ctx *Context) {
|
|
|
@ -24,7 +25,23 @@ func (c Command) Run(ctx *Context) {
|
|
|
|
|
|
|
|
|
|
|
|
set := flagSet(c.Name, c.Flags)
|
|
|
|
set := flagSet(c.Name, c.Flags)
|
|
|
|
set.SetOutput(ioutil.Discard)
|
|
|
|
set.SetOutput(ioutil.Discard)
|
|
|
|
err := set.Parse(ctx.Args()[1:])
|
|
|
|
|
|
|
|
|
|
|
|
firstFlagIndex := -1
|
|
|
|
|
|
|
|
for index, arg := range ctx.Args() {
|
|
|
|
|
|
|
|
if strings.HasPrefix(arg, "-") {
|
|
|
|
|
|
|
|
firstFlagIndex = index
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
if firstFlagIndex > -1 {
|
|
|
|
|
|
|
|
args := ctx.Args()[1:firstFlagIndex]
|
|
|
|
|
|
|
|
flags := ctx.Args()[firstFlagIndex:]
|
|
|
|
|
|
|
|
err = set.Parse(append(flags, args...))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
err = set.Parse(ctx.Args()[1:])
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Incorrect Usage.\n")
|
|
|
|
fmt.Println("Incorrect Usage.\n")
|
|
|
|