1 Commits
Author SHA1 Message Date
terminarandClaude Opus 5.5 975340b5f7 fix(configcmd): config create --output - prints the template to stdout
It wrote a file named "-" in the working directory instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 12:33:03 +01:00
2 changed files with 28 additions and 3 deletions

No files matched your search

+7 -3
View File
@@ -2,7 +2,7 @@
// Yetano program standard (docs/program-conventions.md and ADR-0012 in // Yetano program standard (docs/program-conventions.md and ADR-0012 in
// the yetano meta-repository): // the yetano meta-repository):
// //
// <program> config create [--minimal|--full] [--force] [--output <file>] // <program> config create [--minimal|--full] [--force] [--output <file>|-]
// <program> config validate // <program> config validate
// <program> config upgrade [--write] // <program> config upgrade [--write]
// <program> config path // <program> config path
@@ -201,7 +201,7 @@ func usage(s Spec, w io.Writer) {
} }
fmt.Fprintf(w, `usage: %[1]s config <subcommand> [--config <file>] fmt.Fprintf(w, `usage: %[1]s config <subcommand> [--config <file>]
create [--minimal|--full] [--force] [--output <file>] create [--minimal|--full] [--force] [--output <file>|-]
write a commented starter configuration (minimal by default) write a commented starter configuration (minimal by default)
validate check the configuration file the program would use validate check the configuration file the program would use
upgrade [--write] upgrade [--write]
@@ -342,7 +342,7 @@ func (s Spec) create(explicit string, args []string, stdout, stderr io.Writer) i
minimal := fs.Bool("minimal", false, "write the minimal starter configuration (default)") minimal := fs.Bool("minimal", false, "write the minimal starter configuration (default)")
full := fs.Bool("full", false, "write the fully commented reference configuration") full := fs.Bool("full", false, "write the fully commented reference configuration")
force := fs.Bool("force", false, "overwrite the file if it already exists") force := fs.Bool("force", false, "overwrite the file if it already exists")
output := fs.String("output", "", "file to write (default: --config, else the file the program would use, else "+s.filename()+" in the user config directory -- the system one as root)") output := fs.String("output", "", "file to write, - for stdout (default: --config, else the file the program would use, else "+s.filename()+" in the user config directory -- the system one as root)")
if code := parse(fs, args); code >= 0 { if code := parse(fs, args); code >= 0 {
return code return code
} }
@@ -356,6 +356,10 @@ func (s Spec) create(explicit string, args []string, stdout, stderr io.Writer) i
} }
path := *output path := *output
if path == "-" { // the template on stdout, nothing written
io.WriteString(stdout, content)
return ExitOK
}
if path == "" { if path == "" {
var err error var err error
if path, err = s.defaultCreatePath(explicit); err != nil { if path, err = s.defaultCreatePath(explicit); err != nil {
+21
View File
@@ -190,6 +190,27 @@ func TestCreateExplicitAndOutput(t *testing.T) {
} }
} }
// --output - prints the template and writes no file (not one named "-").
func TestCreateOutputStdout(t *testing.T) {
root := t.TempDir()
s := testSpec(root)
work := filepath.Join(root, "work")
if err := os.MkdirAll(work, 0o755); err != nil {
t.Fatal(err)
}
t.Chdir(work)
code, out, errOut := run(t, s, "", "create", "--full", "--output", "-")
if code != ExitOK || out != fullTemplate || errOut != "" {
t.Fatalf("create --output -: exit %d, stdout %q, stderr %q", code, out, errOut)
}
if _, err := os.Stat(filepath.Join(work, "-")); !errors.Is(err, os.ErrNotExist) {
t.Errorf("create --output - wrote a file named \"-\": %v", err)
}
if code, out, _ := run(t, s, "", "create", "--output=-"); code != ExitOK || out != minimalTemplate {
t.Errorf("create --output=-: exit %d, stdout %q", code, out)
}
}
func TestValidate(t *testing.T) { func TestValidate(t *testing.T) {
root := t.TempDir() root := t.TempDir()
s := testSpec(root) s := testSpec(root)