Skip to content

Commit

Permalink
fix: remove read from os.Stdin (#64)
Browse files Browse the repository at this point in the history
cmd/openapi always reads from a file, so remove the option to read from
stdin, and fail if no input is provided.
  • Loading branch information
julieqiu authored Nov 1, 2024
1 parent 9386ff4 commit 5364920
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions generator/cmd/openapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main

import (
"flag"
"io"
"log"
"log/slog"
"os"
Expand All @@ -32,9 +31,11 @@ func main() {
templateDir := flag.String("template-dir", "templates/", "the path to the template directory")
flag.Parse()

if *inputPath == "" {
log.Fatalf("must provide input-path")
}
if err := run(*inputPath, *language, *outDir, *templateDir); err != nil {
log.Fatal(err)
os.Exit(1)
}
slog.Info("Generation Completed Successfully")
}
Expand All @@ -44,16 +45,9 @@ func run(inputPath, language, outDir, templateDir string) error {
contents []byte
err error
)
if inputPath == "" {
contents, err = io.ReadAll(os.Stdin)
if err != nil {
return err
}
} else {
contents, err = os.ReadFile(inputPath)
if err != nil {
return err
}
contents, err = os.ReadFile(inputPath)
if err != nil {
return err
}
return generateFrom(contents, language, outDir, templateDir)
}
Expand All @@ -71,10 +65,8 @@ func generateFrom(contents []byte, language, outDir, templateDir string) error {
if err != nil {
return err
}

if _, err := genclient.Generate(req); err != nil {
return err
}

return nil
}

0 comments on commit 5364920

Please sign in to comment.