1
0
mirror of https://github.com/go-task/task.git synced 2025-06-06 23:46:46 +02:00

Use github.com/spf13/pflag instead of stdlib flag

This commit is contained in:
Andrey Nering 2017-03-01 20:43:27 -03:00
parent 131499b66d
commit f899df2e82
2 changed files with 10 additions and 9 deletions

View File

@ -1,16 +1,16 @@
package main package main
import ( import (
"flag"
"fmt" "fmt"
"github.com/go-task/task" "github.com/go-task/task"
"github.com/spf13/pflag"
) )
func main() { func main() {
flag.CommandLine.Usage = func() { pflag.Usage = func() {
fmt.Println(` fmt.Println(`task [target1 target2 ...]: Runs commands under targets like make.
task [target1 target2 ...]: Runs commands under targets like make.
Example: 'task hello' with the following 'Taskfile.yml' file will generate Example: 'task hello' with the following 'Taskfile.yml' file will generate
an 'output.txt' file. an 'output.txt' file.
@ -23,8 +23,9 @@ hello:
- output.txt - output.txt
''' '''
`) `)
pflag.PrintDefaults()
} }
flag.BoolVar(&task.Force, "f", false, "forces execution even when the task is up-to-date") pflag.BoolVarP(&task.Force, "force", "f", false, "forces execution even when the task is up-to-date")
flag.Parse() pflag.Parse()
task.Run() task.Run()
} }

View File

@ -3,7 +3,6 @@ package task
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
@ -11,6 +10,7 @@ import (
"os/exec" "os/exec"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"github.com/spf13/pflag"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
@ -22,7 +22,7 @@ var (
// ShPath constains the Bash path if found // ShPath constains the Bash path if found
ShPath string 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 Force bool
// Tasks constains the tasks parsed from Taskfile // Tasks constains the tasks parsed from Taskfile
@ -68,7 +68,7 @@ func (err *taskRunError) Error() string {
func Run() { func Run() {
log.SetFlags(0) log.SetFlags(0)
args := flag.Args() args := pflag.Args()
if len(args) == 0 { if len(args) == 0 {
log.Fatal("No argument given") log.Fatal("No argument given")
} }