Explain framework configuration paths safely
This commit is contained in:
@@ -12,7 +12,9 @@ import (
|
||||
|
||||
type frameworkConfigurationConfig struct {
|
||||
mode, configPath, configOverlay, schemaDir string
|
||||
path string
|
||||
configExplicit bool
|
||||
pathExplicit bool
|
||||
overrides []configkit.Override
|
||||
diagnostics []configkit.Diagnostic
|
||||
}
|
||||
@@ -39,6 +41,14 @@ func inspectFrameworkConfigurationCommand(args []string, stdout, stderr io.Write
|
||||
writeApplicationError(stderr, "inspect configuration parse", err)
|
||||
return ExitRuntimeError
|
||||
}
|
||||
var explanationPath configkit.Path
|
||||
if cfg.mode == "explain" {
|
||||
explanationPath, err = configkit.ParsePath(cfg.path)
|
||||
if err != nil {
|
||||
writeApplicationError(stderr, "inspect configuration path", err)
|
||||
return ExitRuntimeError
|
||||
}
|
||||
}
|
||||
settings, err := resolveAppSettingsForFrameworkConfiguration(cfg)
|
||||
if err != nil {
|
||||
writeApplicationError(stderr, "inspect configuration", err)
|
||||
@@ -64,6 +74,18 @@ func inspectFrameworkConfigurationCommand(args []string, stdout, stderr io.Write
|
||||
return ExitOK
|
||||
}
|
||||
|
||||
if cfg.mode == "explain" {
|
||||
if _, ok := view.Explain(explanationPath); !ok {
|
||||
writeApplicationError(stderr, "inspect configuration path", fmt.Errorf("unknown path %q", cfg.path))
|
||||
return ExitRuntimeError
|
||||
}
|
||||
if err := view.WriteExplanation(stdout, explanationPath); err != nil {
|
||||
fmt.Fprintf(stderr, "inspect configuration output error: %v\n", err)
|
||||
return ExitRuntimeError
|
||||
}
|
||||
return ExitOK
|
||||
}
|
||||
|
||||
switch cfg.mode {
|
||||
case "show":
|
||||
err = view.WriteEffective(stdout)
|
||||
@@ -84,7 +106,7 @@ func parseFrameworkConfigurationArgs(args []string) (*frameworkConfigurationConf
|
||||
}
|
||||
cfg := &frameworkConfigurationConfig{mode: args[0]}
|
||||
switch cfg.mode {
|
||||
case "validate", "show", "sources":
|
||||
case "validate", "show", "sources", "explain":
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown configuration operation %q", cfg.mode)
|
||||
}
|
||||
@@ -95,6 +117,7 @@ func parseFrameworkConfigurationArgs(args []string) (*frameworkConfigurationConf
|
||||
var promptkitSources promptKitSourceFlagValue
|
||||
fs.Var(&promptkitSources, "promptkit-source", "selected PromptKit source path (repeatable)")
|
||||
fs.StringVar(&cfg.schemaDir, "schema-dir", "", "base directory for validation schemas")
|
||||
fs.StringVar(&cfg.path, "path", "", "JSON Pointer to explain (required for explain)")
|
||||
if err := fs.Parse(args[1:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -102,6 +125,10 @@ func parseFrameworkConfigurationArgs(args []string) (*frameworkConfigurationConf
|
||||
return nil, fmt.Errorf("unexpected positional args: %v", fs.Args())
|
||||
}
|
||||
cfg.configExplicit = flagWasSet(fs, "config")
|
||||
cfg.pathExplicit = flagWasSet(fs, "path")
|
||||
if cfg.mode == "explain" && !cfg.pathExplicit {
|
||||
return nil, errors.New("--path is required for explain")
|
||||
}
|
||||
cfg.overrides = applicationOverrides(fs)
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user