diff --git a/cmd/task/task.go b/cmd/task/task.go index 746d7f0b..8a9b7d5e 100644 --- a/cmd/task/task.go +++ b/cmd/task/task.go @@ -1,16 +1,16 @@ package main import ( - "flag" "fmt" "github.com/go-task/task" + + "github.com/spf13/pflag" ) func main() { - flag.CommandLine.Usage = func() { - fmt.Println(` -task [target1 target2 ...]: Runs commands under targets like make. + pflag.Usage = func() { + fmt.Println(`task [target1 target2 ...]: Runs commands under targets like make. Example: 'task hello' with the following 'Taskfile.yml' file will generate an 'output.txt' file. @@ -23,8 +23,9 @@ hello: - output.txt ''' `) + pflag.PrintDefaults() } - flag.BoolVar(&task.Force, "f", false, "forces execution even when the task is up-to-date") - flag.Parse() + pflag.BoolVarP(&task.Force, "force", "f", false, "forces execution even when the task is up-to-date") + pflag.Parse() task.Run() } diff --git a/task.go b/task.go index a354a1b6..52bc1ac5 100644 --- a/task.go +++ b/task.go @@ -3,7 +3,6 @@ package task import ( "encoding/json" "errors" - "flag" "fmt" "io/ioutil" "log" @@ -11,6 +10,7 @@ import ( "os/exec" "github.com/BurntSushi/toml" + "github.com/spf13/pflag" "gopkg.in/yaml.v2" ) @@ -22,7 +22,7 @@ var ( // ShPath constains the Bash path if found ShPath string - // Force (-f flag) forces a task to run even when it's up-to-date + // Force (--force or -f flag) forces a task to run even when it's up-to-date Force bool // Tasks constains the tasks parsed from Taskfile @@ -68,7 +68,7 @@ func (err *taskRunError) Error() string { func Run() { log.SetFlags(0) - args := flag.Args() + args := pflag.Args() if len(args) == 0 { log.Fatal("No argument given") }