Skip to content

feat(cli): -r/--refresh flag overrides list auto-refresh interval - #3

Open
posquit0 wants to merge 2 commits into
mainfrom
feat/qw8-refresh-flag
Open

feat(cli): -r/--refresh flag overrides list auto-refresh interval#3
posquit0 wants to merge 2 commits into
mainfrom
feat/qw8-refresh-flag

Conversation

@posquit0

@posquit0 posquit0 commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary

  • k9s uses -r 2 for poll cadence. ota's DefaultRefreshInterval was config-only
  • Add -r/--refresh <sec> flag that overrides both DefaultRefreshInterval and LogsRefreshInterval
  • Zero (default) falls through to the config value; positive value wins

Files

  • cmd/ota/main.go — register flag under both -r and --refresh (shared float64 target)
  • cmd/ota/wire.goresolveDefaultRefreshInterval + resolveLogsRefreshInterval
  • cmd/ota/wire_test.go — resolver semantics + CLI parsing contract

Test plan

  • go test ./... -race -count=1 green
  • manual: ota -r 5, watch Users list poll every 5s

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new CLI flag -r / --refresh to override the auto-refresh intervals for lists and logs in the ota tool, along with corresponding resolution helper functions and unit tests. The reviewer feedback highlights an inconsistency where 0 is used as the default CLI flag value (meaning "use config") but represents "disable auto-refresh" in the configuration file. To resolve this, the reviewer suggests changing the default CLI flag value to -1 (to mean "use config") so that 0 can be used via the CLI to explicitly disable auto-refresh. Additionally, the reviewer recommends enforcing a minimum refresh interval safeguard of 500ms to prevent UI thread starvation and API rate-limiting, and updating the resolution logic and unit tests to match these new semantics.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread cmd/ota/main.go Outdated
Comment on lines +64 to +66
var refreshSec float64
fs.Float64Var(&refreshSec, "r", 0, "list auto-refresh interval in seconds (overrides config; 0 = use config)")
fs.Float64Var(&refreshSec, "refresh", 0, "list auto-refresh interval in seconds (overrides config; 0 = use config)")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In the configuration file, a value of 0 is used to disable auto-refresh. However, in the CLI flags, 0 is used as the default value to mean "use config". This inconsistency makes it impossible for a user to explicitly disable auto-refresh via the CLI if it is enabled in the configuration file.

To resolve this inconsistency and allow disabling auto-refresh via the CLI, we can change the default value of the CLI flags to -1 (representing "use config") and let 0 explicitly mean "disable auto-refresh", matching the configuration file's semantics.

Suggested change
var refreshSec float64
fs.Float64Var(&refreshSec, "r", 0, "list auto-refresh interval in seconds (overrides config; 0 = use config)")
fs.Float64Var(&refreshSec, "refresh", 0, "list auto-refresh interval in seconds (overrides config; 0 = use config)")
var refreshSec float64
fs.Float64Var(&refreshSec, "r", -1, "list auto-refresh interval in seconds (overrides config; 0 = disable, -1 = use config)")
fs.Float64Var(&refreshSec, "refresh", -1, "list auto-refresh interval in seconds (overrides config; 0 = disable, -1 = use config)")

Comment thread cmd/ota/wire.go
Comment on lines +189 to +194
func resolveDefaultRefreshInterval(cfg config.RefreshConfig, overrideSec float64) time.Duration {
if overrideSec > 0 {
return time.Duration(overrideSec * float64(time.Second))
}
return time.Duration(cfg.DefaultSeconds) * time.Second
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To support the new -1 default value (representing "use config") and allow 0 to explicitly disable auto-refresh, we should update resolveDefaultRefreshInterval to check overrideSec >= 0.

Additionally, we should enforce a reasonable minimum refresh interval (e.g., 500 * time.Millisecond) for any positive override to prevent UI thread starvation and Okta API rate-limiting if a user accidentally passes an extremely small value (e.g., -r 0.001).

func resolveDefaultRefreshInterval(cfg config.RefreshConfig, overrideSec float64) time.Duration {
	if overrideSec >= 0 {
		if overrideSec == 0 {
			return 0
		}
		d := time.Duration(overrideSec * float64(time.Second))
		const minInterval = 500 * time.Millisecond
		if d < minInterval {
			return minInterval
		}
		return d
	}
	return time.Duration(cfg.DefaultSeconds) * time.Second
}

Comment thread cmd/ota/wire.go
Comment on lines +200 to +205
func resolveLogsRefreshInterval(cfg config.RefreshConfig, overrideSec float64) time.Duration {
if overrideSec > 0 {
return time.Duration(overrideSec * float64(time.Second))
}
return time.Duration(cfg.LogsSeconds) * time.Second
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To support the new -1 default value (representing "use config") and allow 0 to explicitly disable auto-refresh, we should update resolveLogsRefreshInterval to check overrideSec >= 0.

Additionally, we should enforce a reasonable minimum refresh interval (e.g., 500 * time.Millisecond) for any positive override to prevent UI thread starvation and Okta API rate-limiting if a user accidentally passes an extremely small value (e.g., -r 0.001).

func resolveLogsRefreshInterval(cfg config.RefreshConfig, overrideSec float64) time.Duration {
	if overrideSec >= 0 {
		if overrideSec == 0 {
			return 0
		}
		d := time.Duration(overrideSec * float64(time.Second))
		const minInterval = 500 * time.Millisecond
		if d < minInterval {
			return minInterval
		}
		return d
	}
	return time.Duration(cfg.LogsSeconds) * time.Second
}

Comment thread cmd/ota/wire_test.go
Comment on lines +18 to +46
func Test_ResolveRefreshInterval_CLIOverridesConfig(t *testing.T) {
cfg := config.RefreshConfig{LogsSeconds: 10, DefaultSeconds: 10}

t.Run("cli override wins on both surfaces", func(t *testing.T) {
assert.Equal(t, 2*time.Second, resolveDefaultRefreshInterval(cfg, 2))
assert.Equal(t, 2*time.Second, resolveLogsRefreshInterval(cfg, 2))
})

t.Run("fractional seconds honored", func(t *testing.T) {
assert.Equal(t, 500*time.Millisecond, resolveDefaultRefreshInterval(cfg, 0.5))
assert.Equal(t, 500*time.Millisecond, resolveLogsRefreshInterval(cfg, 0.5))
})

t.Run("zero override falls through to config", func(t *testing.T) {
assert.Equal(t, 10*time.Second, resolveDefaultRefreshInterval(cfg, 0))
assert.Equal(t, 10*time.Second, resolveLogsRefreshInterval(cfg, 0))
})

t.Run("negative override treated as no override", func(t *testing.T) {
assert.Equal(t, 10*time.Second, resolveDefaultRefreshInterval(cfg, -3))
assert.Equal(t, 10*time.Second, resolveLogsRefreshInterval(cfg, -3))
})

t.Run("cli override wins even when config disables auto-refresh", func(t *testing.T) {
disabled := config.RefreshConfig{LogsSeconds: 0, DefaultSeconds: 0}
assert.Equal(t, 2*time.Second, resolveDefaultRefreshInterval(disabled, 2))
assert.Equal(t, 2*time.Second, resolveLogsRefreshInterval(disabled, 2))
})
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Update the unit tests to align with the new CLI override semantics: -1 represents "use config", 0 explicitly disables auto-refresh, and positive values below 500ms are capped to the minimum interval safeguard.

func Test_ResolveRefreshInterval_CLIOverridesConfig(t *testing.T) {
	cfg := config.RefreshConfig{LogsSeconds: 10, DefaultSeconds: 10}

	t.Run("cli override wins on both surfaces", func(t *testing.T) {
		assert.Equal(t, 2*time.Second, resolveDefaultRefreshInterval(cfg, 2))
		assert.Equal(t, 2*time.Second, resolveLogsRefreshInterval(cfg, 2))
	})

	t.Run("fractional seconds honored", func(t *testing.T) {
		assert.Equal(t, 500*time.Millisecond, resolveDefaultRefreshInterval(cfg, 0.5))
		assert.Equal(t, 500*time.Millisecond, resolveLogsRefreshInterval(cfg, 0.5))
	})

	t.Run("extremely small fractional seconds capped to minimum", func(t *testing.T) {
		assert.Equal(t, 500*time.Millisecond, resolveDefaultRefreshInterval(cfg, 0.1))
		assert.Equal(t, 500*time.Millisecond, resolveLogsRefreshInterval(cfg, 0.1))
	})

	t.Run("zero override disables auto-refresh", func(t *testing.T) {
		assert.Equal(t, 0*time.Second, resolveDefaultRefreshInterval(cfg, 0))
		assert.Equal(t, 0*time.Second, resolveLogsRefreshInterval(cfg, 0))
	})

	t.Run("negative override (default -1) falls through to config", func(t *testing.T) {
		assert.Equal(t, 10*time.Second, resolveDefaultRefreshInterval(cfg, -1))
		assert.Equal(t, 10*time.Second, resolveLogsRefreshInterval(cfg, -1))
	})

	t.Run("cli override wins even when config disables auto-refresh", func(t *testing.T) {
		disabled := config.RefreshConfig{LogsSeconds: 0, DefaultSeconds: 0}
		assert.Equal(t, 2*time.Second, resolveDefaultRefreshInterval(disabled, 2))
		assert.Equal(t, 2*time.Second, resolveLogsRefreshInterval(disabled, 2))
	})
}

posquit0 added 2 commits July 5, 2026 23:50
k9s uses -r 2 to set the poll cadence. ota's DefaultRefreshInterval was
config-only. Add a CLI flag so operators can override without touching config.

- cmd/ota/main.go: register -r and --refresh (shared float64 target)
- cmd/ota/wire.go: resolveDefaultRefreshInterval + resolveLogsRefreshInterval
  apply the CLI override to both surfaces; zero falls through to cfg.Refresh
- cmd/ota/wire_test.go: resolver semantics + CLI parsing contract
Reworks the -r/--refresh semantics from PR review feedback:

- Flag default is now -1 ("use config") so that 0 can mean explicit disable,
  matching the config file semantics.
- resolveDefaultRefreshInterval / resolveLogsRefreshInterval accept any
  non-negative override (0 disables, positive clamps up to a 500ms floor)
  and only fall through to config on negative values.
- Sub-500ms polling is clamped up to 500ms to avoid self-inflicted 429s.
- Tests updated to cover negative-uses-config, zero-disables, small-positive
  clamped-to-floor, and positive-above-floor pass-through.
@posquit0
posquit0 force-pushed the feat/qw8-refresh-flag branch from f95e869 to 7355c52 Compare July 5, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant