Skip to content

Commit d5ab2c2

Browse files
RobertKwiatkowskiFoxboron
authored andcommitted
Add quiet flag
Included quiet option to disable stdout logging when asked to Fixes #128 Signed-off-by: Morten Linderud <[email protected]>
1 parent e2c0d7b commit d5ab2c2

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cmd/sbctl/main.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import (
1313
)
1414

1515
type CmdOptions struct {
16-
JsonOutput bool
16+
JsonOutput bool
17+
QuietOutput bool
1718
}
1819

1920
type cliCommand struct {
@@ -45,11 +46,15 @@ Please read the FAQ for more information: https://github.com/Foxboron/sbctl/wiki
4546
func baseFlags(cmd *cobra.Command) {
4647
flags := cmd.PersistentFlags()
4748
flags.BoolVar(&cmdOptions.JsonOutput, "json", false, "Output as json")
49+
flags.BoolVar(&cmdOptions.QuietOutput, "quiet", false, "Mute info from logging")
4850

4951
cmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
5052
if cmdOptions.JsonOutput {
5153
logging.PrintOff()
5254
}
55+
if cmdOptions.QuietOutput {
56+
logging.DisableInfo = true
57+
}
5358
}
5459
}
5560

logging/logging.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ var (
2929
)
3030

3131
var (
32-
on bool
33-
output io.Writer = os.Stdout
32+
on bool
33+
DisableInfo bool = false
34+
output io.Writer = os.Stdout
3435
)
3536

3637
func PrintOn() {
@@ -52,10 +53,16 @@ func PrintWithFile(f io.Writer, msg string, a ...interface{}) {
5253
}
5354

5455
func Print(msg string, a ...interface{}) {
56+
if DisableInfo && output == os.Stdout {
57+
return
58+
}
5559
PrintWithFile(output, msg, a...)
5660
}
5761

5862
func Println(msg string) {
63+
if DisableInfo && output == os.Stdout {
64+
return
65+
}
5966
PrintWithFile(output, msg+"\n")
6067
}
6168

0 commit comments

Comments
 (0)