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

View File

@ -100,6 +100,7 @@ var (
// authSecretIsHex is used to recall whether the encryption secret was
// determined to be pure hex.
encrSecretIsHex bool
quiet bool
)
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")
slogger = slogging.SetLevel(slogging.LevelDebug)
@ -278,3 +279,8 @@ func dhallCmdExists() bool {
return true
}
// BeQuiet instruct this package to be more frugal with logging/printing info.
func BeQuiet() {
quiet = true
}

22
run.go
View File

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