Skip to content

Commit

Permalink
Support '-' as output argument, meaning standard output.
Browse files Browse the repository at this point in the history
  • Loading branch information
atombender committed Feb 20, 2019
1 parent a010b5e commit 5408067
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions pkg/generator/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ func (g *Generator) Sources() map[string][]byte {
}

func (g *Generator) DoFile(fileName string) error {
f, err := os.Open(fileName)
f, closer, err := openFileArg(fileName)
if err != nil {
return err
}
defer func() {
_ = f.Close()
_ = closer()
}()

schema, err := schemas.FromReader(f)
Expand Down Expand Up @@ -823,3 +823,11 @@ func fileExists(fileName string) bool {
_, err := os.Stat(fileName)
return err == nil || !os.IsNotExist(err)
}

func openFileArg(arg string) (io.Reader, func() error, error) {
if arg == "-" {
return os.Stdin, func() error { return nil }, nil
}
f, err := os.Open(arg)
return f, f.Close, err
}

0 comments on commit 5408067

Please sign in to comment.