mirror of
https://github.com/go-task/task.git
synced 2024-12-14 10:52:43 +02:00
Merge pull request #613 from Peter554/fix-quoting-cli-args
Fix quoting of CLI_ARGS
This commit is contained in:
commit
846c27d579
@ -12,6 +12,7 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
"mvdan.cc/sh/v3/syntax"
|
||||||
|
|
||||||
"github.com/go-task/task/v3"
|
"github.com/go-task/task/v3"
|
||||||
"github.com/go-task/task/v3/args"
|
"github.com/go-task/task/v3/args"
|
||||||
@ -161,16 +162,20 @@ func main() {
|
|||||||
var (
|
var (
|
||||||
calls []taskfile.Call
|
calls []taskfile.Call
|
||||||
globals *taskfile.Vars
|
globals *taskfile.Vars
|
||||||
tasksAndVars, cliArgs = getArgs()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
tasksAndVars, cliArgs, err := getArgs()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if v >= 3.0 {
|
if v >= 3.0 {
|
||||||
calls, globals = args.ParseV3(tasksAndVars...)
|
calls, globals = args.ParseV3(tasksAndVars...)
|
||||||
} else {
|
} else {
|
||||||
calls, globals = args.ParseV2(tasksAndVars...)
|
calls, globals = args.ParseV2(tasksAndVars...)
|
||||||
}
|
}
|
||||||
|
|
||||||
globals.Set("CLI_ARGS", taskfile.Var{Static: strings.Join(cliArgs, " ")})
|
globals.Set("CLI_ARGS", taskfile.Var{Static: cliArgs})
|
||||||
e.Taskfile.Vars.Merge(globals)
|
e.Taskfile.Vars.Merge(globals)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
@ -191,20 +196,25 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getArgs() (tasksAndVars, cliArgs []string) {
|
func getArgs() ([]string, string, error) {
|
||||||
var (
|
var (
|
||||||
args = pflag.Args()
|
args = pflag.Args()
|
||||||
doubleDashPos = pflag.CommandLine.ArgsLenAtDash()
|
doubleDashPos = pflag.CommandLine.ArgsLenAtDash()
|
||||||
)
|
)
|
||||||
|
|
||||||
if doubleDashPos != -1 {
|
if doubleDashPos == -1 {
|
||||||
tasksAndVars = args[:doubleDashPos]
|
return args, "", nil
|
||||||
cliArgs = args[doubleDashPos:]
|
|
||||||
} else {
|
|
||||||
tasksAndVars = args
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
quotedCliArgs := []string{}
|
||||||
|
for _, arg := range args[doubleDashPos:] {
|
||||||
|
quotedCliArg, err := syntax.Quote(arg, syntax.LangBash)
|
||||||
|
if err != nil {
|
||||||
|
return []string{}, "", err
|
||||||
|
}
|
||||||
|
quotedCliArgs = append(quotedCliArgs, quotedCliArg)
|
||||||
|
}
|
||||||
|
return args[:doubleDashPos], strings.Join(quotedCliArgs, " "), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSignalContext() context.Context {
|
func getSignalContext() context.Context {
|
||||||
|
Loading…
Reference in New Issue
Block a user