feat: add --no-update-check flag and disable update check via config (issue #23)

Add support for disabling the automatic update check at startup, which could cause delays on air-gapped or offline machines due to DNS timeouts.

- Add --no-update-check CLI flag for one-time override
- Add check_for_updates field (*bool) to AppConfig with default true
- CLI flag overrides the config file setting (both feed into IsUpdateCheckEnabled)
- Move update check from --version template to TUI Init() only, respecting the new configuration
- Remove getVersionWithUpdateCheck() from cmd/root.go; --version now prints a plain version string
- Rename internal/config/keybindings.go → appconfig.go and keybindings_test.go → appconfig_test.go to reflect the broader scope of the file
- Add TestIsUpdateCheckEnabled with table-driven cases (nil config, nil field, true, false) and extend existing integration test with a CheckForUpdates round-trip
- Update README: document --no-update-check flag, config option, and rename "Custom Key Bindings" section to "Application Configuration"
This commit is contained in:
2026-02-23 21:28:54 +01:00
parent 891fb2a0f4
commit f189cb37e3
6 changed files with 118 additions and 41 deletions

View File

@@ -18,7 +18,16 @@ type KeyBindings struct {
// AppConfig represents the main application configuration
type AppConfig struct {
KeyBindings KeyBindings `json:"key_bindings"`
CheckForUpdates *bool `json:"check_for_updates,omitempty"`
KeyBindings KeyBindings `json:"key_bindings"`
}
// IsUpdateCheckEnabled returns true if the update check is enabled (default: true)
func (c *AppConfig) IsUpdateCheckEnabled() bool {
if c == nil || c.CheckForUpdates == nil {
return true
}
return *c.CheckForUpdates
}
// GetDefaultKeyBindings returns the default key bindings configuration

View File

@@ -104,6 +104,58 @@ func TestAppConfigBasics(t *testing.T) {
if len(defaultConfig.KeyBindings.QuitKeys) != len(expectedQuitKeys) {
t.Errorf("Expected %d quit keys, got %d", len(expectedQuitKeys), len(defaultConfig.KeyBindings.QuitKeys))
}
// CheckForUpdates should be nil by default
if defaultConfig.CheckForUpdates != nil {
t.Error("Default configuration should have CheckForUpdates as nil")
}
// IsUpdateCheckEnabled should return true by default
if !defaultConfig.IsUpdateCheckEnabled() {
t.Error("IsUpdateCheckEnabled should return true when CheckForUpdates is nil")
}
}
func boolPtr(b bool) *bool {
return &b
}
func TestIsUpdateCheckEnabled(t *testing.T) {
tests := []struct {
name string
config *AppConfig
expected bool
}{
{
name: "nil AppConfig returns true",
config: nil,
expected: true,
},
{
name: "CheckForUpdates nil returns true",
config: &AppConfig{},
expected: true,
},
{
name: "CheckForUpdates true returns true",
config: &AppConfig{CheckForUpdates: boolPtr(true)},
expected: true,
},
{
name: "CheckForUpdates false returns false",
config: &AppConfig{CheckForUpdates: boolPtr(false)},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result := tt.config.IsUpdateCheckEnabled()
if result != tt.expected {
t.Errorf("IsUpdateCheckEnabled() = %v, expected %v", result, tt.expected)
}
})
}
}
func TestMergeWithDefaults(t *testing.T) {
@@ -141,6 +193,7 @@ func TestSaveAndLoadAppConfigIntegration(t *testing.T) {
configPath := filepath.Join(tempDir, "config.json")
customConfig := AppConfig{
CheckForUpdates: boolPtr(false),
KeyBindings: KeyBindings{
QuitKeys: []string{"q"},
DisableEscQuit: true,
@@ -178,4 +231,15 @@ func TestSaveAndLoadAppConfigIntegration(t *testing.T) {
if len(loadedConfig.KeyBindings.QuitKeys) != 1 || loadedConfig.KeyBindings.QuitKeys[0] != "q" {
t.Errorf("Expected quit keys to be ['q'], got %v", loadedConfig.KeyBindings.QuitKeys)
}
// Verify CheckForUpdates is correctly persisted and reloaded
if loadedConfig.CheckForUpdates == nil {
t.Fatal("CheckForUpdates should not be nil after round-trip")
}
if *loadedConfig.CheckForUpdates != false {
t.Errorf("CheckForUpdates should be false after round-trip, got %v", *loadedConfig.CheckForUpdates)
}
if loadedConfig.IsUpdateCheckEnabled() {
t.Error("IsUpdateCheckEnabled should return false when CheckForUpdates is false")
}
}

View File

@@ -16,7 +16,7 @@ import (
)
// NewModel creates a new TUI model with the given SSH hosts
func NewModel(hosts []config.SSHHost, configFile string, searchMode bool, currentVersion string) Model {
func NewModel(hosts []config.SSHHost, configFile string, searchMode bool, currentVersion string, noUpdateCheck bool) Model {
// Load application configuration
appConfig, err := config.LoadAppConfig()
if err != nil {
@@ -26,6 +26,12 @@ func NewModel(hosts []config.SSHHost, configFile string, searchMode bool, curren
appConfig = &defaultConfig
}
// CLI flag overrides config file setting
if noUpdateCheck {
f := false
appConfig.CheckForUpdates = &f
}
// Initialize the history manager
historyManager, err := history.NewHistoryManager()
if err != nil {
@@ -151,8 +157,8 @@ func NewModel(hosts []config.SSHHost, configFile string, searchMode bool, curren
}
// RunInteractiveMode starts the interactive TUI interface
func RunInteractiveMode(hosts []config.SSHHost, configFile string, searchMode bool, currentVersion string) error {
m := NewModel(hosts, configFile, searchMode, currentVersion)
func RunInteractiveMode(hosts []config.SSHHost, configFile string, searchMode bool, currentVersion string, noUpdateCheck bool) error {
m := NewModel(hosts, configFile, searchMode, currentVersion, noUpdateCheck)
// Start the application in alt screen mode for clean output
p := tea.NewProgram(m, tea.WithAltScreen())

View File

@@ -74,8 +74,8 @@ func (m Model) Init() tea.Cmd {
// Basic initialization commands
cmds = append(cmds, textinput.Blink)
// Check for version updates if we have a current version
if m.currentVersion != "" {
// Check for version updates if we have a current version and updates are enabled
if m.currentVersion != "" && m.appConfig.IsUpdateCheckEnabled() {
cmds = append(cmds, checkVersionCmd(m.currentVersion))
}