Skip to content
Snippets Groups Projects
Commit 81a893c2 authored by Christophe de Vienne's avatar Christophe de Vienne
Browse files

generate-config: defaults to 'stdout'

parent 17d9acf1
No related branches found
No related tags found
No related merge requests found
......@@ -2,9 +2,11 @@
import (
"fmt"
"io"
"os"
flags "github.com/orus-io/go-flags"
)
// ConfigWrite is a command that generates a configuration file.
type ConfigWrite struct {
......@@ -5,10 +7,10 @@
flags "github.com/orus-io/go-flags"
)
// ConfigWrite is a command that generates a configuration file.
type ConfigWrite struct {
Output string `short:"o" long:"output" default:"config.ini" no-ini:"t" description:"output file"`
Output string `short:"o" long:"output" default:"-" no-ini:"t" description:"output file"`
parser *flags.Parser
}
......@@ -22,7 +24,22 @@
func (c *ConfigWrite) Execute([]string) error {
fp := flags.NewIniParser(c.parser)
return fp.WriteFile(c.Output, flags.IniIncludeDefaults|flags.IniCommentDefaults|flags.IniDefault)
var output io.Writer
if c.Output == "-" {
output = os.Stdout
} else {
f, err := os.Create(c.Output)
if err != nil {
return err
}
defer f.Close()
output = f
}
fp.Write(output, flags.IniIncludeDefaults|flags.IniCommentDefaults|flags.IniDefault)
return nil
}
func parseFile(parser *flags.Parser) func(string) error {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment