Skip to content

refactor: decompose screen_reachability.go updateConfig() nested switch #205

Description

@nathanhuh

Summary

`updateConfig()` in `internal/app/screen_reachability.go` is a 68-line function with 3-level nesting handling 13 key cases that manage protocol selection, port input, IP input, and form navigation simultaneously. Tracing a single key event requires reading the entire function.

Details

  • Switch-within-switch-within-switch structure makes control flow hard to follow
  • All 13 input cases live in one function, mixing orthogonal concerns
  • Adding a new form field requires understanding all existing cases

Checklist

  • Extract `handleProtocolInput(msg tea.KeyMsg) (reachabilityModel, tea.Cmd)`
  • Extract `handlePortInput(msg tea.KeyMsg) (reachabilityModel, tea.Cmd)`
  • Extract `handleIPInput(msg tea.KeyMsg) (reachabilityModel, tea.Cmd)`
  • Reduce outer `updateConfig()` to a dispatcher that routes to the appropriate handler based on current form focus state
  • Verify existing reachability tests still pass

References

  • `internal/app/screen_reachability.go:415-483`

Raised from senior code review (2026-05-12).

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions