Skip to content

Commit

Permalink
Add a --ignore_unknown flag to query whatinputs (#3057)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterebden authored Feb 8, 2024
1 parent c339ee1 commit 97d2267
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/please.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,10 @@ var opts struct {
} `positional-args:"true"`
} `command:"graph" description:"Prints a representation of the build graph."`
WhatInputs struct {
Hidden bool `long:"hidden" short:"h" description:"Output internal / hidden targets too."`
EchoFiles bool `long:"echo_files" description:"Echo the file for which the printed output is responsible."`
Args struct {
Hidden bool `long:"hidden" short:"h" description:"Output internal / hidden targets too."`
EchoFiles bool `long:"echo_files" description:"Echo the file for which the printed output is responsible."`
IgnoreUnknown bool `long:"ignore_unknown" description:"Ignore any files that are not inputs to existing build targets"`
Args struct {
Files cli.StdinStrings `positional-arg-name:"files" description:"Files to query as sources to targets" required:"true"`
} `positional-args:"true" required:"true"`
} `command:"whatinputs" description:"Prints out target(s) with provided file(s) as inputs"`
Expand Down Expand Up @@ -883,7 +884,7 @@ var buildFunctions = map[string]func() int{
labels = append(labels, core.FindOwningPackage(state, file))
}
return runQuery(true, labels, func(state *core.BuildState) {
query.WhatInputs(state.Graph, files, opts.Query.WhatInputs.Hidden, opts.Query.WhatInputs.EchoFiles)
query.WhatInputs(state.Graph, files, opts.Query.WhatInputs.Hidden, opts.Query.WhatInputs.EchoFiles, opts.Query.WhatInputs.IgnoreUnknown)
})
},
"query.whatoutputs": func() int {
Expand Down
4 changes: 2 additions & 2 deletions src/query/whatinputs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// WhatInputs prints the targets with the provided files as sources
// The targets are printed in the same order as the provided files, separated by a newline
// Use printFiles to additionally echo the files themselves (i.e. print <file> <target>)
func WhatInputs(graph *core.BuildGraph, files []string, hidden, printFiles bool) {
func WhatInputs(graph *core.BuildGraph, files []string, hidden, printFiles, ignoreUnknown bool) {
targets := graph.AllTargets()

for _, file := range files {
Expand All @@ -21,7 +21,7 @@ func WhatInputs(graph *core.BuildGraph, files []string, hidden, printFiles bool)
}
fmt.Printf("%s\n", label)
}
} else {
} else if !ignoreUnknown {
log.Fatalf("%s is not a source to any current target", file)
}
}
Expand Down

0 comments on commit 97d2267

Please sign in to comment.