2017-09-07 18:57:06 +02:00
|
|
|
package args
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
2023-12-29 22:32:03 +02:00
|
|
|
"github.com/go-task/task/v3/taskfile/ast"
|
2017-09-07 18:57:06 +02:00
|
|
|
)
|
|
|
|
|
2023-12-29 22:26:02 +02:00
|
|
|
// Parse parses command line argument: tasks and global variables
|
2024-01-26 16:34:18 +02:00
|
|
|
func Parse(args ...string) ([]*ast.Call, *ast.Vars) {
|
|
|
|
calls := []*ast.Call{}
|
2023-12-29 22:32:03 +02:00
|
|
|
globals := &ast.Vars{}
|
2020-08-17 02:26:10 +02:00
|
|
|
|
|
|
|
for _, arg := range args {
|
|
|
|
if !strings.Contains(arg, "=") {
|
2024-01-26 16:34:18 +02:00
|
|
|
calls = append(calls, &ast.Call{Task: arg})
|
2020-08-17 02:26:10 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
name, value := splitVar(arg)
|
2023-12-29 22:32:03 +02:00
|
|
|
globals.Set(name, ast.Var{Value: value})
|
2020-08-17 02:26:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return calls, globals
|
|
|
|
}
|
|
|
|
|
2019-05-11 16:06:47 +02:00
|
|
|
func splitVar(s string) (string, string) {
|
|
|
|
pair := strings.SplitN(s, "=", 2)
|
|
|
|
return pair[0], pair[1]
|
2017-09-07 18:57:06 +02:00
|
|
|
}
|