Skip to content

Commit 26f40e6

Browse files
authored
Merge pull request #94 from Peefy/feat-add-queit-for-all-mod-cmd
feat: add queit mode for all mod cmd
2 parents dc2b9a8 + 85f65b8 commit 26f40e6

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

Diff for: cmd/kcl/commands/mod.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,27 @@ var (
4343

4444
// NewModCmd returns the mod command.
4545
func NewModCmd() *cobra.Command {
46+
reporter.InitReporter()
47+
cli, err := client.NewKpmClient()
48+
if err != nil {
49+
panic(err)
50+
}
4651
cmd := &cobra.Command{
4752
Use: "mod",
4853
Short: "KCL module management",
4954
Long: modDesc,
5055
Example: modExample,
5156
SilenceUsage: true,
57+
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
58+
if quiet {
59+
cli.SetLogWriter(nil)
60+
}
61+
return nil
62+
},
5263
}
5364

5465
cmd.PersistentFlags().BoolVarP(&quiet, "quiet", "q", false, "Set the quiet mode (no output)")
5566

56-
reporter.InitReporter()
57-
cli, err := client.NewKpmClient()
58-
if err != nil {
59-
panic(err)
60-
}
61-
if quiet {
62-
cli.SetLogWriter(nil)
63-
}
64-
6567
cmd.AddCommand(NewModInitCmd(cli))
6668
cmd.AddCommand(NewModAddCmd(cli))
6769
cmd.AddCommand(NewModPkgCmd(cli))

Diff for: pkg/options/run.go

+3
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ func (o *RunOptions) Run() error {
101101
}
102102
}()
103103
opts := CompileOptionFromCli(o)
104+
if o.Quiet {
105+
opts.SetLogWriter(nil)
106+
}
104107
if err != nil {
105108
return err
106109
}

0 commit comments

Comments
 (0)