Skip to content

Implement watch command: re-analyze on file change #15

@oksaumya

Description

@oksaumya

Summary

optiqor watch [chart] is registered as a Cobra subcommand but returns notYetImplemented. The roadmap (Tier 2) calls for a file-watcher that re-runs analysis whenever a watched values file or chart directory changes — useful for tightening a chart iteratively.

Desired behaviour

optiqor watch ./my-chart
# Clears screen, prints analysis, then waits.
# On any *.yaml change under ./my-chart → clears, re-prints.
# Ctrl-C exits cleanly.

What to do

  1. Choose a file-watcher library. fsnotify/fsnotify is the idiomatic Go choice and already used by many Cobra CLIs. Add it to go.mod.
  2. Create internal/watch/watch.go with a Run(path string, opts Options) error that:
    • Calls analyze.RunPath(path) once on start.
    • Sets up an fsnotify.Watcher on the chart directory (recursive glob **/*.yaml).
    • On WRITE/CREATE/REMOVE events, debounces 200 ms, then re-runs analysis and reprints.
    • Clears the terminal between runs (ANSI \033[H\033[2J when IsTTY).
    • On SIGINT / SIGTERM, shuts down cleanly (exit code 0).
  3. Wire watchCmd in cmd/optiqor/main.go to call watch.Run.
  4. Support --json (stream newline-delimited JSON events instead of clearing screen).

Acceptance criteria

  • optiqor watch ./testdata/fixtures/basic-chart starts, prints findings, and reprints on YAML edit.
  • --json streams {"event":"update","findings":[...]} lines.
  • Ctrl-C exits with code 0.
  • make lint test passes (use a temporary directory + file write in the test to trigger a re-run).

Notes

  • Keep the binary size in mind — fsnotify adds ~200 KB, which is fine.
  • Windows is explicitly out of scope per CLAUDE.md; fsnotify still works but is not a test target.

Metadata

Metadata

Assignees

Labels

claimedSomeone has claimed this via /assignenhancementNew feature or requesthelp wantedExtra attention is needed

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions