Skip to content

Commit

Permalink
cmd/sqlc: Show helpful output on missing subcommand (sqlc-dev#2345)
Browse files Browse the repository at this point in the history
Also use the cobra helpers to avoid printing to stdout directly
  • Loading branch information
kyleconroy committed Jun 20, 2023
1 parent 8d365df commit f086636
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ func Do(args []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) int
rootCmd.SetIn(stdin)
rootCmd.SetOut(stdout)
rootCmd.SetErr(stderr)
rootCmd.SilenceErrors = true

ctx := context.Background()
if debug.Debug.Trace != "" {
Expand Down Expand Up @@ -79,9 +78,9 @@ var versionCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
defer trace.StartRegion(cmd.Context(), "version").End()
if version == "" {
fmt.Printf("%s\n", info.Version)
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", info.Version)
} else {
fmt.Printf("%s\n", version)
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", version)
}
return nil
},
Expand Down Expand Up @@ -191,7 +190,7 @@ var genCmd = &cobra.Command{
dir, name := getConfigPath(stderr, cmd.Flag("file"))
output, err := Generate(cmd.Context(), ParseEnv(cmd), dir, name, stderr)
if err != nil {
return err
os.Exit(1)
}
defer trace.StartRegion(cmd.Context(), "writefiles").End()
for filename, source := range output {
Expand Down

0 comments on commit f086636

Please sign in to comment.