handleWatchStartCommand starts a K8s watcher in background from interactive mode.
(ctx context.Context, args []string)
| 42 | |
| 43 | // handleWatchStartCommand starts a K8s watcher in background from interactive mode. |
| 44 | func (ch *CommandHandler) handleWatchStartCommand(ctx context.Context, args []string) { |
| 45 | if ch.cli.isWatching { |
| 46 | fmt.Println(colorize(i18n.T("watch.error.already_running"), ColorYellow)) |
| 47 | return |
| 48 | } |
| 49 | |
| 50 | // Parse flags (same manual pattern as /connect) |
| 51 | cfg := k8s.WatchConfig{ |
| 52 | Namespace: "default", |
| 53 | Interval: 30 * time.Second, |
| 54 | Window: 2 * time.Hour, |
| 55 | MaxLogLines: 100, |
| 56 | } |
| 57 | |
| 58 | for i := 0; i < len(args); i++ { |
| 59 | switch args[i] { |
| 60 | case "--deployment": |
| 61 | if i+1 < len(args) { |
| 62 | i++ |
| 63 | cfg.Deployment = args[i] |
| 64 | } |
| 65 | case "--kind": |
| 66 | if i+1 < len(args) { |
| 67 | i++ |
| 68 | cfg.Kind = args[i] |
| 69 | } |
| 70 | case "--namespace": |
| 71 | if i+1 < len(args) { |
| 72 | i++ |
| 73 | cfg.Namespace = args[i] |
| 74 | } |
| 75 | case "--interval": |
| 76 | if i+1 < len(args) { |
| 77 | i++ |
| 78 | d, err := time.ParseDuration(args[i]) |
| 79 | if err != nil { |
| 80 | fmt.Println(colorize(i18n.T("watch.error.invalid_flag", "--interval", err.Error()), ColorYellow)) |
| 81 | return |
| 82 | } |
| 83 | cfg.Interval = d |
| 84 | } |
| 85 | case "--window": |
| 86 | if i+1 < len(args) { |
| 87 | i++ |
| 88 | d, err := time.ParseDuration(args[i]) |
| 89 | if err != nil { |
| 90 | fmt.Println(colorize(i18n.T("watch.error.invalid_flag", "--window", err.Error()), ColorYellow)) |
| 91 | return |
| 92 | } |
| 93 | cfg.Window = d |
| 94 | } |
| 95 | case "--max-log-lines": |
| 96 | if i+1 < len(args) { |
| 97 | i++ |
| 98 | n, err := strconv.Atoi(args[i]) |
| 99 | if err != nil { |
| 100 | fmt.Println(colorize(i18n.T("watch.error.invalid_flag", "--max-log-lines", err.Error()), ColorYellow)) |
| 101 | return |
no test coverage detected