Skip to content

Commit f086636

Browse files
authored
cmd/sqlc: Show helpful output on missing subcommand (sqlc-dev#2345)
Also use the cobra helpers to avoid printing to stdout directly
1 parent 8d365df commit f086636

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

internal/cmd/cmd.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func Do(args []string, stdin io.Reader, stdout io.Writer, stderr io.Writer) int
4949
rootCmd.SetIn(stdin)
5050
rootCmd.SetOut(stdout)
5151
rootCmd.SetErr(stderr)
52-
rootCmd.SilenceErrors = true
5352

5453
ctx := context.Background()
5554
if debug.Debug.Trace != "" {
@@ -79,9 +78,9 @@ var versionCmd = &cobra.Command{
7978
RunE: func(cmd *cobra.Command, args []string) error {
8079
defer trace.StartRegion(cmd.Context(), "version").End()
8180
if version == "" {
82-
fmt.Printf("%s\n", info.Version)
81+
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", info.Version)
8382
} else {
84-
fmt.Printf("%s\n", version)
83+
fmt.Fprintf(cmd.OutOrStdout(), "%s\n", version)
8584
}
8685
return nil
8786
},
@@ -191,7 +190,7 @@ var genCmd = &cobra.Command{
191190
dir, name := getConfigPath(stderr, cmd.Flag("file"))
192191
output, err := Generate(cmd.Context(), ParseEnv(cmd), dir, name, stderr)
193192
if err != nil {
194-
return err
193+
os.Exit(1)
195194
}
196195
defer trace.StartRegion(cmd.Context(), "writefiles").End()
197196
for filename, source := range output {

0 commit comments

Comments
 (0)