func NewTargetedCodeGeneratorFromConfig(
	configuration *config.Configuration, idFactory astmodel.IdentifierFactory, target PipelineTarget) (*CodeGenerator, error) {
	result, err := NewCodeGeneratorFromConfig(configuration, idFactory)
	if err != nil {
		return nil, errors.Wrapf(err, "creating pipeline targeting %v", target)
	}
	var stages []PipelineStage
	for _, s := range result.pipeline {
		if s.IsUsedFor(target) {
			stages = append(stages, s)
		}
	}
	result.pipeline = stages
	err = result.verifyPipeline()
	if err != nil {
		return nil, err
	}
	return result, nil
}
NewTargetedCodeGeneratorFromConfig produces a new code generator with the given configuration and
only the stages appropriate for the specfied target.
package codegen
import (
	"context"
	"fmt"
	"github.com/pkg/errors"
	kerrors "k8s.io/apimachinery/pkg/util/errors"
	"k8s.io/klog/v2"
	"github.com/Azure/k8s-infra/hack/generator/pkg/astmodel"
	"github.com/Azure/k8s-infra/hack/generator/pkg/config"
)
type CodeGenerator struct {
	configuration *config.Configuration
	pipeline      []PipelineStage
}
func translatePipelineToTarget(pipeline config.GenerationPipeline) (PipelineTarget, error) {
	switch pipeline {
	case config.GenerationPipelineAzure:
		return ARMTarget, nil
	case config.GenerationPipelineCrossplane:
		return CrossplaneTarget, nil
	default:
		return PipelineTarget{}, errors.Errorf("unknown pipeline target kind %s", pipeline)
	}
}
func NewCodeGeneratorFromConfigFile(configurationFile string) (*CodeGenerator, error) {
	configuration, err := config.LoadConfiguration(configurationFile)
	if err != nil {
		return nil, err
	}
	target, err := translatePipelineToTarget(configuration.Pipeline)
	if err != nil {
		return nil, err
	}
	return NewTargetedCodeGeneratorFromConfig(configuration, astmodel.NewIdentifierFactory(), target)
}