go: add a way to reduce printing
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
surtur 2023-08-13 18:06:24 +02:00
parent 9b4aa6e370
commit 7c8650019e
Signed by: wanderer
SSH Key Fingerprint: SHA256:MdCZyJ2sHLltrLBp0xQO0O1qTW9BT/xl5nXkDvhlMCI
2 changed files with 21 additions and 9 deletions

@ -100,6 +100,7 @@ var (
// authSecretIsHex is used to recall whether the encryption secret was // authSecretIsHex is used to recall whether the encryption secret was
// determined to be pure hex. // determined to be pure hex.
encrSecretIsHex bool encrSecretIsHex bool
quiet bool
) )
func Load(conf string, isPath bool) (*Config, error) { func Load(conf string, isPath bool) (*Config, error) {
@ -141,7 +142,7 @@ func Load(conf string, isPath bool) (*Config, error) {
) )
} }
if config.DevelMode && os.Getenv("PCMT_DEVEL") != "False" { if config.DevelMode && os.Getenv("PCMT_DEVEL") != "False" && !quiet {
log.Debug("set DEBUG level based on config value") log.Debug("set DEBUG level based on config value")
slogger = slogging.SetLevel(slogging.LevelDebug) slogger = slogging.SetLevel(slogging.LevelDebug)
@ -278,3 +279,8 @@ func dhallCmdExists() bool {
return true return true
} }
// BeQuiet instruct this package to be more frugal with logging/printing info.
func BeQuiet() {
quiet = true
}

22
run.go

@ -80,21 +80,25 @@ func run() error { //nolint:gocognit
return nil return nil
} }
// skip printing program header. // skip printing program header and some other stuff.
skipHeader := false shortCircuit := false
var doingImport bool var doingImport bool
if importFlag != nil && *importFlag != "" { if importFlag != nil && *importFlag != "" {
doingImport = true doingImport = true
skipHeader = true shortCircuit = true
config.BeQuiet()
} }
if *printMigrationFlag { if *printMigrationFlag {
skipHeader = true shortCircuit = true
config.BeQuiet()
} }
if !skipHeader { if !shortCircuit {
printHeader() printHeader()
} }
@ -133,9 +137,11 @@ func run() error { //nolint:gocognit
setting := settings.New() setting := settings.New()
setting.Consolidate( if !shortCircuit {
conf, hostFlag, portFlag, develFlag, version, setting.Consolidate(
) conf, hostFlag, portFlag, develFlag, version,
)
}
// expected connstring form for "github.com/xiaoqidun/entps": // expected connstring form for "github.com/xiaoqidun/entps":
// "file:ent?mode=memory&cache=shared&_fk=1" // "file:ent?mode=memory&cache=shared&_fk=1"