mirror of
https://github.com/davidallendj/configurator.git
synced 2025-12-20 03:27:02 -07:00
Minor refactor to run additional targets recursively
This commit is contained in:
parent
2154657d34
commit
cccbb1ad25
2 changed files with 81 additions and 52 deletions
|
|
@ -9,6 +9,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
configurator "github.com/OpenCHAMI/configurator/internal"
|
||||
"github.com/OpenCHAMI/configurator/internal/generator"
|
||||
"github.com/OpenCHAMI/configurator/internal/util"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
@ -60,6 +61,12 @@ var generateCmd = &cobra.Command{
|
|||
fmt.Printf("%v\n", string(b))
|
||||
}
|
||||
|
||||
RunTargets(targets...)
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func RunTargets(config *configurator.Config, targets ...string) {
|
||||
// generate config with each supplied target
|
||||
for _, target := range targets {
|
||||
params := generator.Params{
|
||||
|
|
@ -120,9 +127,13 @@ var generateCmd = &cobra.Command{
|
|||
fmt.Printf("wrote file to '%s'\n", cleanPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
// remove any targets that are the same as current to prevent infinite loop
|
||||
nextTargets := util.CopyIf(config.Targets[targets].Targets, func(t T) bool { return t != target })
|
||||
|
||||
// ...then, run any other targets that the current target has
|
||||
RunTargets(config, nextTargets...)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
|||
|
|
@ -61,3 +61,21 @@ func GitCommit() string {
|
|||
|
||||
return strings.TrimRight(string(stdout), "\n")
|
||||
}
|
||||
|
||||
// NOTE: would it be better to use slices.DeleteFunc instead
|
||||
func RemoveIndex[T comparable](s []T, index int) []T {
|
||||
ret := make([]T, 0)
|
||||
ret = append(ret, s[:index]...)
|
||||
return append(ret, s[index+1:]...)
|
||||
}
|
||||
|
||||
func CopyIf[T comparable](s []T, condition func(t T) bool) []T {
|
||||
var f = make([]T, 0)
|
||||
for _, e := range s {
|
||||
if condition(e) {
|
||||
f = append(f, e)
|
||||
}
|
||||
}
|
||||
|
||||
return f
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue