feat: Add config support for UI verbosity level (#175)

* feat: Add config support for UI verbosity level

* docs: Add verbosity info in UI doc
This commit is contained in:
Abhisek Datta
2026-03-04 13:32:34 +05:30
committed by GitHub
parent 0c09988776
commit 8cba52201c
5 changed files with 29 additions and 0 deletions
+9
View File
@@ -14,6 +14,11 @@ import (
) )
const ( const (
// Verbosity level constants for the config file
VerbositySilent = "silent"
VerbosityNormal = "normal"
VerbosityVerbose = "verbose"
// Environment variable key for the insecure installation flag // Environment variable key for the insecure installation flag
pmgInsecureInstallationEnvKey = "PMG_INSECURE_INSTALLATION" pmgInsecureInstallationEnvKey = "PMG_INSECURE_INSTALLATION"
@@ -64,6 +69,9 @@ type Config struct {
// we initially introduced it as an experimental feature. // we initially introduced it as an experimental feature.
ExperimentalProxyMode bool `mapstructure:"experimental_proxy_mode"` ExperimentalProxyMode bool `mapstructure:"experimental_proxy_mode"`
// Verbosity controls the UI verbosity level. Valid values: "silent", "normal", "verbose".
Verbosity string `mapstructure:"verbosity"`
// Sandbox enables sandboxing of package manager processes with controlled filesystem, // Sandbox enables sandboxing of package manager processes with controlled filesystem,
// network, and process execution access. Provides defense-in-depth against supply chain attacks. // network, and process execution access. Provides defense-in-depth against supply chain attacks.
Sandbox SandboxConfig `mapstructure:"sandbox"` Sandbox SandboxConfig `mapstructure:"sandbox"`
@@ -211,6 +219,7 @@ func DefaultConfig() RuntimeConfig {
ExperimentalProxyMode: false, ExperimentalProxyMode: false,
TrustedPackages: []TrustedPackage{}, TrustedPackages: []TrustedPackage{},
ProxyMode: true, ProxyMode: true,
Verbosity: VerbosityNormal,
Sandbox: SandboxConfig{ Sandbox: SandboxConfig{
Enabled: false, Enabled: false,
EnforceAlways: false, EnforceAlways: false,
+6
View File
@@ -10,6 +10,12 @@ transitive_depth: 5
# Include dev dependencies in the dependency graph. Default is false. # Include dev dependencies in the dependency graph. Default is false.
include_dev_dependencies: false include_dev_dependencies: false
# UI verbosity level. Valid values: silent, normal, verbose. Default is normal.
# silent: PMG is hidden from the user except for errors and malicious package detection
# normal: Show minimal status updates
# verbose: Show verbose status updates and detailed information
verbosity: normal
# Enable paranoid mode. In paranoid mode, PMG will treat suspicious packages # Enable paranoid mode. In paranoid mode, PMG will treat suspicious packages
# as malicious packages # as malicious packages
paranoid: false paranoid: false
+1
View File
@@ -54,6 +54,7 @@ func TestTemplateMatchesDefaults(t *testing.T) {
assert.Equal(t, def.Paranoid, parsed.Paranoid, "paranoid mismatch") assert.Equal(t, def.Paranoid, parsed.Paranoid, "paranoid mismatch")
assert.Equal(t, def.SkipEventLogging, parsed.SkipEventLogging, "skip_event_logging mismatch") assert.Equal(t, def.SkipEventLogging, parsed.SkipEventLogging, "skip_event_logging mismatch")
assert.Equal(t, def.EventLogRetentionDays, parsed.EventLogRetentionDays, "event_log_retention_days mismatch") assert.Equal(t, def.EventLogRetentionDays, parsed.EventLogRetentionDays, "event_log_retention_days mismatch")
assert.Equal(t, def.Verbosity, parsed.Verbosity, "verbosity mismatch")
assert.NotEmpty(t, parsed.TrustedPackages, "expected at least one trusted_packages entry") assert.NotEmpty(t, parsed.TrustedPackages, "expected at least one trusted_packages entry")
+2
View File
@@ -2,6 +2,8 @@
PMG is an interactive tool. We support multiple interactivity modes such as `silent`, `verbose` etc. to meet different developer experience needs. As such, we need to standardize the UI, UX and interactive messaging guidance for developers. PMG is an interactive tool. We support multiple interactivity modes such as `silent`, `verbose` etc. to meet different developer experience needs. As such, we need to standardize the UI, UX and interactive messaging guidance for developers.
The verbosity level can be set per-invocation using `--silent` or `--verbose` CLI flags, or persisted via the `verbosity` option in the [configuration file](config.md).
## Messaging ## Messaging
Two types of messages to users are supported: Two types of messages to users are supported:
+11
View File
@@ -47,6 +47,17 @@ func main() {
os.Setenv("APP_LOG_SKIP_STDOUT_LOGGER", "true") os.Setenv("APP_LOG_SKIP_STDOUT_LOGGER", "true")
} }
// Apply config-based verbosity first
switch config.Get().Config.Verbosity {
case config.VerbositySilent:
ui.SetVerbosityLevel(ui.VerbosityLevelSilent)
case config.VerbosityVerbose:
ui.SetVerbosityLevel(ui.VerbosityLevelVerbose)
default:
ui.SetVerbosityLevel(ui.VerbosityLevelNormal)
}
// CLI flags override config
if silent && verbose { if silent && verbose {
ui.Fatalf("pmg: --silent and --verbose cannot be used together") ui.Fatalf("pmg: --silent and --verbose cannot be used together")
} }