这是indexloc提供的服务,不要输入任何密码
Skip to content

Allow and hash pass through CLI args #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions internal/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,15 @@ func (c *RunCommand) Run(args []string) int {
pipeline = altpipe
}
hashable := struct {
Hash string
Task string
Outputs []string
Hash string
Task string
Outputs []string
PassThruArgs []string
}{
Hash: pack.Hash,
Task: task,
Outputs: pipeline.Outputs,
Hash: pack.Hash,
Task: task,
Outputs: pipeline.Outputs,
PassThruArgs: runOptions.passThroughArgs,
}
hash, err := fs.HashObject(hashable)
targetLogger.Debug("task hash", "value", hash)
Expand Down Expand Up @@ -478,6 +480,7 @@ func (c *RunCommand) Run(args []string) int {
targetUi.Output(fmt.Sprintf("cache miss, executing %s", ui.Dim(hash)))
}
argsactual := append([]string{"run"}, task)
argsactual = append(argsactual, runOptions.passThroughArgs...)
// @TODO: @jaredpalmer fix this hack to get the package manager's name
cmd := exec.Command(strings.TrimPrefix(ctx.Backend.Name, "nodejs-"), argsactual...)
cmd.Dir = pack.Dir
Expand Down Expand Up @@ -687,21 +690,23 @@ type RunOptions struct {
// Cache folder
cacheFolder string
// Immediately exit on task failure
bail bool
bail bool
passThroughArgs []string
}

func getDefaultRunOptions() *RunOptions {
return &RunOptions{
bail: true,
deps: true,
parallel: false,
concurrency: 10,
dotGraph: "",
ancestors: false,
cache: true,
profile: "", // empty string does no tracing
forceExecution: false,
stream: true,
bail: true,
deps: true,
parallel: false,
concurrency: 10,
dotGraph: "",
ancestors: false,
cache: true,
profile: "", // empty string does no tracing
forceExecution: false,
stream: true,
passThroughArgs: []string{},
}
}

Expand All @@ -714,8 +719,11 @@ func parseRunArgs(args []string, cwd string) (*RunOptions, error) {

unresolvedCacheFolder := "./node_modules/.cache/turbo"

for _, arg := range args {
if strings.HasPrefix(arg, "--") {
for argIndex, arg := range args {
if arg == "--" {
runOptions.passThroughArgs = args[argIndex+1:]
break
} else if strings.HasPrefix(arg, "--") {
switch {
case strings.HasPrefix(arg, "--since="):
if len(arg[len("--since="):]) > 1 {
Expand Down
34 changes: 34 additions & 0 deletions internal/run/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,40 @@ func TestParseConfig(t *testing.T) {
cacheFolder: "node_modules/.cache/turbo",
},
},
{
"passThroughArgs",
[]string{"foo", "--graph=g.png", "--", "--boop", "zoop"},
&RunOptions{
deps: true,
stream: true,
bail: true,
dotGraph: "g.png",
concurrency: 10,
ancestors: false,
cache: true,
forceExecution: false,
profile: "",
cacheFolder: "node_modules/.cache/turbo",
passThroughArgs: []string{"--boop", "zoop"},
},
},
{
"Empty passThroughArgs",
[]string{"foo", "--graph=g.png", "--"},
&RunOptions{
deps: true,
stream: true,
bail: true,
dotGraph: "g.png",
concurrency: 10,
ancestors: false,
cache: true,
forceExecution: false,
profile: "",
cacheFolder: "node_modules/.cache/turbo",
passThroughArgs: []string{},
},
},
}

for i, tc := range cases {
Expand Down