Fixed issue with generate and added some documentation to funcs

This commit is contained in:
David Allen 2024-07-08 16:11:10 -06:00
parent 7494468bed
commit cd840b2bf0
No known key found for this signature in database
GPG key ID: 717C593FF60A2ACC
9 changed files with 219 additions and 158 deletions

View file

@ -55,7 +55,7 @@ func init() {
fetchCmd.Flags().IntVar(&remotePort, "port", 3334, "set the remote configurator port")
fetchCmd.Flags().StringSliceVar(&targets, "target", nil, "set the target configs to make")
fetchCmd.Flags().StringVarP(&outputPath, "output", "o", "", "set the output path for config targets")
fetchCmd.Flags().StringVar(&accessToken, "access-token", "o", "", "set the output path for config targets")
fetchCmd.Flags().StringVar(&accessToken, "access-token", "o", "set the output path for config targets")
rootCmd.AddCommand(fetchCmd)
}

View file

@ -61,12 +61,12 @@ var generateCmd = &cobra.Command{
fmt.Printf("%v\n", string(b))
}
RunTargets(targets...)
RunTargets(&config, args, targets...)
},
}
func RunTargets(config *configurator.Config, targets ...string) {
func RunTargets(config *configurator.Config, args []string, targets ...string) {
// generate config with each supplied target
for _, target := range targets {
params := generator.Params{
@ -75,13 +75,13 @@ func RunTargets(config *configurator.Config, targets ...string) {
Target: target,
Verbose: verbose,
}
outputBytes, err := generator.Generate(&config, params)
outputBytes, err := generator.Generate(config, params)
if err != nil {
fmt.Printf("failed to generate config: %v\n", err)
os.Exit(1)
}
outputMap := util.ConvertMapOutput(outputBytes)
outputMap := generator.ConvertContentsToString(outputBytes)
// if we have more than one target and output is set, create configs in directory
var (
@ -129,10 +129,10 @@ func RunTargets(config *configurator.Config, targets ...string) {
}
// 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 })
nextTargets := util.CopyIf(config.Targets[target].RunTargets, func(t string) bool { return t != target })
// ...then, run any other targets that the current target has
RunTargets(config, nextTargets...)
RunTargets(config, args, nextTargets...)
}
}

View file

@ -10,6 +10,7 @@ import (
)
var (
byTarget bool
pluginDirs []string
generators map[string]generator.Generator
)
@ -17,6 +18,7 @@ var (
var inspectCmd = &cobra.Command{
Use: "inspect",
Short: "Inspect generator plugin information",
Long: "The 'inspect' sub-command takes a list of directories and prints all found plugin information.",
Run: func(cmd *cobra.Command, args []string) {
// load specific plugins from positional args
generators = make(map[string]generator.Generator)
@ -26,6 +28,10 @@ var inspectCmd = &cobra.Command{
fmt.Printf("failed to load plugin at path '%s': %v\n", path, err)
continue
}
// path is directory, so no plugin is loaded, but no error was returned
if gen == nil {
continue
}
generators[path] = gen
}
@ -59,5 +65,6 @@ var inspectCmd = &cobra.Command{
}
func init() {
inspectCmd.Flags().BoolVar(&byTarget, "by-target", false, "set whether to ")
rootCmd.AddCommand(inspectCmd)
}