Adopt ConfigKit overlays for pipeline selection
This commit is contained in:
@@ -20,8 +20,8 @@ type configDiffFlags struct {
|
||||
}
|
||||
|
||||
type configDiffRequest struct {
|
||||
leftProfile string
|
||||
rightProfile string
|
||||
leftOverlay string
|
||||
rightOverlay string
|
||||
flags configDiffFlags
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ type configDiffRecord struct {
|
||||
Right string
|
||||
}
|
||||
|
||||
// ConfigDiff compares two explicitly selected profiles through the same
|
||||
// ConfigDiff compares two explicitly selected overlays through the same
|
||||
// read-only configuration resolution boundary used by config validate, show,
|
||||
// and sources. Differences describe normalized effective values rather than
|
||||
// the layout of root, import, or overlay files.
|
||||
@@ -100,7 +100,7 @@ func configDiffWithDependencies(_ context.Context, args []string, out io.Writer,
|
||||
}
|
||||
|
||||
func parseConfigDiffRequest(args []string, out io.Writer) (configDiffRequest, error) {
|
||||
profiles, flagArgs := splitConfigDiffArguments(args)
|
||||
overlays, flagArgs := splitConfigDiffArguments(args)
|
||||
fs := flag.NewFlagSet("config diff", flag.ContinueOnError)
|
||||
fs.SetOutput(out)
|
||||
var request configDiffRequest
|
||||
@@ -113,9 +113,9 @@ func parseConfigDiffRequest(args []string, out io.Writer) (configDiffRequest, er
|
||||
fs.Var(&request.flags.campaignFilePath, "campaign-file", "path to campaign.yml")
|
||||
fs.Var(&request.flags.secretsDir, "secrets-dir", "secrets directory (optional; defaults beside pipeline.yml)")
|
||||
fs.Usage = func() {
|
||||
fmt.Fprintln(out, "Usage: narratio config diff <left-profile> <right-profile> [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--secrets-dir <path>]")
|
||||
fmt.Fprintln(out, "Usage: narratio config diff <left-overlay> <right-overlay> [--config <pipeline.yml>] [--campaign <id> | --campaign-file <campaign.yml>] [--secrets-dir <path>]")
|
||||
fmt.Fprintln(out)
|
||||
fmt.Fprintln(out, "Compares fully resolved profiles without a session, workspace, manifest, adapters, or external services.")
|
||||
fmt.Fprintln(out, "Compares fully resolved overlays without a session, workspace, manifest, adapters, or external services.")
|
||||
fmt.Fprintln(out)
|
||||
fmt.Fprintln(out, "Flags:")
|
||||
fs.PrintDefaults()
|
||||
@@ -123,30 +123,30 @@ func parseConfigDiffRequest(args []string, out io.Writer) (configDiffRequest, er
|
||||
if err := fs.Parse(flagArgs); err != nil {
|
||||
return configDiffRequest{}, fmt.Errorf("config diff: invalid flags: %w", err)
|
||||
}
|
||||
profiles = append(profiles, fs.Args()...)
|
||||
if len(profiles) != 2 || strings.TrimSpace(profiles[0]) == "" || strings.TrimSpace(profiles[1]) == "" {
|
||||
return configDiffRequest{}, fmt.Errorf("config diff: exactly two non-empty profile names are required")
|
||||
overlays = append(overlays, fs.Args()...)
|
||||
if len(overlays) != 2 || strings.TrimSpace(overlays[0]) == "" || strings.TrimSpace(overlays[1]) == "" {
|
||||
return configDiffRequest{}, fmt.Errorf("config diff: exactly two non-empty overlay names are required")
|
||||
}
|
||||
if profiles[0] == profiles[1] {
|
||||
return configDiffRequest{}, fmt.Errorf("config diff: profile names must differ")
|
||||
if overlays[0] == overlays[1] {
|
||||
return configDiffRequest{}, fmt.Errorf("config diff: overlay names must differ")
|
||||
}
|
||||
if request.flags.campaignPath.set && request.flags.campaignFilePath.set {
|
||||
return configDiffRequest{}, fmt.Errorf("config diff: --campaign and --campaign-file are mutually exclusive")
|
||||
}
|
||||
request.leftProfile = profiles[0]
|
||||
request.rightProfile = profiles[1]
|
||||
request.leftOverlay = overlays[0]
|
||||
request.rightOverlay = overlays[1]
|
||||
return request, nil
|
||||
}
|
||||
|
||||
// splitConfigDiffArguments accepts the documented positional-first syntax and
|
||||
// also permits flags before or between profile names. Values belonging to the
|
||||
// also permits flags before or between overlay names. Values belonging to the
|
||||
// supported string flags stay with their flag so they are not mistaken for
|
||||
// profile names.
|
||||
func splitConfigDiffArguments(args []string) (profiles, flagArgs []string) {
|
||||
// overlay names.
|
||||
func splitConfigDiffArguments(args []string) (overlays, flagArgs []string) {
|
||||
for index := 0; index < len(args); index++ {
|
||||
argument := args[index]
|
||||
if !strings.HasPrefix(argument, "-") || argument == "-" {
|
||||
profiles = append(profiles, argument)
|
||||
overlays = append(overlays, argument)
|
||||
continue
|
||||
}
|
||||
flagArgs = append(flagArgs, argument)
|
||||
@@ -161,12 +161,12 @@ func splitConfigDiffArguments(args []string) (profiles, flagArgs []string) {
|
||||
index++
|
||||
flagArgs = append(flagArgs, args[index])
|
||||
}
|
||||
return profiles, flagArgs
|
||||
return overlays, flagArgs
|
||||
}
|
||||
|
||||
func configDiffStringFlag(name string) bool {
|
||||
switch name {
|
||||
case "config", "campaign", "campaign-file", "profile", "secrets-dir":
|
||||
case "config", "campaign", "campaign-file", "secrets-dir":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
@@ -175,13 +175,13 @@ func configDiffStringFlag(name string) bool {
|
||||
|
||||
func resolveConfigDiff(request configDiffRequest, deps commandDependencies) (*configDiffResolved, error) {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
pipelinePath, leftPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Profile: &request.leftProfile}, request.flags.secretsDir.pointer(), deps)
|
||||
pipelinePath, leftPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Overlay: &request.leftOverlay}, request.flags.secretsDir.pointer(), deps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load left pipeline profile: %w", err)
|
||||
return nil, fmt.Errorf("load left pipeline overlay: %w", err)
|
||||
}
|
||||
_, rightPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Profile: &request.rightProfile}, request.flags.secretsDir.pointer(), deps)
|
||||
_, rightPipeline, err := loadPipelineConfigWithDependencies(request.flags.pipelinePath.value, config.PipelineLoadOptions{Overlay: &request.rightOverlay}, request.flags.secretsDir.pointer(), deps)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load right pipeline profile: %w", err)
|
||||
return nil, fmt.Errorf("load right pipeline overlay: %w", err)
|
||||
}
|
||||
needsCampaign := pipelineHasArtifactFamilies(leftPipeline) || pipelineHasArtifactFamilies(rightPipeline)
|
||||
hasCampaignSelection := request.flags.campaignPath.set || request.flags.campaignFilePath.set
|
||||
@@ -259,7 +259,7 @@ func resolveSharedDiffCampaignPath(left, right *config.PipelineConfig, flags con
|
||||
return "", rightErr
|
||||
}
|
||||
if leftPath != rightPath {
|
||||
return "", fmt.Errorf("profile selections resolve different campaign files; specify --campaign-file to compare one campaign")
|
||||
return "", fmt.Errorf("overlay selections resolve different campaign files; specify --campaign-file to compare one campaign")
|
||||
}
|
||||
return leftPath, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user