Compare commits
1
Commits
gui/v0.3.0
...
v0.12.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
975340b5f7 |
No files matched your search
@@ -2,7 +2,7 @@
|
||||
// Yetano program standard (docs/program-conventions.md and ADR-0012 in
|
||||
// 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 upgrade [--write]
|
||||
// <program> config path
|
||||
@@ -201,7 +201,7 @@ func usage(s Spec, w io.Writer) {
|
||||
}
|
||||
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)
|
||||
validate check the configuration file the program would use
|
||||
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)")
|
||||
full := fs.Bool("full", false, "write the fully commented reference configuration")
|
||||
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 {
|
||||
return code
|
||||
}
|
||||
@@ -356,6 +356,10 @@ func (s Spec) create(explicit string, args []string, stdout, stderr io.Writer) i
|
||||
}
|
||||
|
||||
path := *output
|
||||
if path == "-" { // the template on stdout, nothing written
|
||||
io.WriteString(stdout, content)
|
||||
return ExitOK
|
||||
}
|
||||
if path == "" {
|
||||
var err error
|
||||
if path, err = s.defaultCreatePath(explicit); err != nil {
|
||||
|
||||
@@ -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) {
|
||||
root := t.TempDir()
|
||||
s := testSpec(root)
|
||||
|
||||
Reference in new issue
Block a user