|
| 1 | +package cli |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + |
| 6 | + "github.com/flashcatcloud/flashduty-cli/internal/output" |
| 7 | +) |
| 8 | + |
| 9 | +// colSpec is a display-only column for the generic table renderer: which row |
| 10 | +// field to show, its header, and an optional width cap. It NEVER affects flags or |
| 11 | +// json/toon output — a wrong entry degrades a single table column at worst, it |
| 12 | +// can't cause a functional error. Field is the Go struct field name on the row |
| 13 | +// type; timestamp fields are detected and formatted automatically. Format, when |
| 14 | +// set, renders the raw field value with a semantic formatter (percent, duration) |
| 15 | +// the default scalar rendering doesn't apply — display-only, like the rest. |
| 16 | +type colSpec struct { |
| 17 | + Header string |
| 18 | + Field string |
| 19 | + MaxWidth int |
| 20 | + Format func(any) string |
| 21 | +} |
| 22 | + |
| 23 | +// fmtPercent renders a 0..1 ratio as a whole-number percentage ("85%"), matching |
| 24 | +// the curated insight tables. A non-float value yields "". |
| 25 | +func fmtPercent(v any) string { |
| 26 | + if f, ok := v.(float64); ok { |
| 27 | + return fmt.Sprintf("%.0f%%", f*100) |
| 28 | + } |
| 29 | + return "" |
| 30 | +} |
| 31 | + |
| 32 | +// fmtSecondsDuration renders a seconds count (int or float) as a human duration |
| 33 | +// ("2m 30s"), matching the curated insight MTTA/MTTR/engaged columns. |
| 34 | +func fmtSecondsDuration(v any) string { |
| 35 | + switch n := v.(type) { |
| 36 | + case float64: |
| 37 | + return output.FormatDurationFloat(n) |
| 38 | + case int64: |
| 39 | + return output.FormatDuration(int(n)) |
| 40 | + case int: |
| 41 | + return output.FormatDuration(n) |
| 42 | + default: |
| 43 | + return "" |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +// displayColumns maps a go-flashduty response row type (by Go type name) to its |
| 48 | +// human table columns, seeded from the hand-written column sets the curated |
| 49 | +// commands used before the CLI converged on generated commands. Row types with |
| 50 | +// no entry fall back to the reflective heuristic in generic_table.go. |
| 51 | +// |
| 52 | +// Names are intentionally not resolved here (e.g. ChannelItem shows TEAM_ID / |
| 53 | +// CREATOR_ID, not team/creator names): id→name enrichment belongs in the API |
| 54 | +// response, not the client. Until the API carries those names, the table shows |
| 55 | +// the ids; json/toon is unaffected either way. |
| 56 | +var displayColumns = map[string][]colSpec{ |
| 57 | + "IncidentInfo": { |
| 58 | + {Header: "ID", Field: "IncidentID"}, |
| 59 | + {Header: "TITLE", Field: "Title", MaxWidth: 50}, |
| 60 | + {Header: "SEVERITY", Field: "IncidentSeverity"}, |
| 61 | + {Header: "PROGRESS", Field: "Progress"}, |
| 62 | + {Header: "CHANNEL", Field: "ChannelName"}, |
| 63 | + {Header: "CREATED", Field: "StartTime"}, |
| 64 | + }, |
| 65 | + "PastIncidentItem": { |
| 66 | + {Header: "ID", Field: "IncidentID"}, |
| 67 | + {Header: "TITLE", Field: "Title", MaxWidth: 50}, |
| 68 | + {Header: "SEVERITY", Field: "IncidentSeverity"}, |
| 69 | + {Header: "PROGRESS", Field: "Progress"}, |
| 70 | + {Header: "CHANNEL", Field: "ChannelName"}, |
| 71 | + {Header: "CREATED", Field: "StartTime"}, |
| 72 | + }, |
| 73 | + "AlertInfo": { |
| 74 | + {Header: "ALERT_ID", Field: "AlertID"}, |
| 75 | + {Header: "TITLE", Field: "Title", MaxWidth: 50}, |
| 76 | + {Header: "SEVERITY", Field: "AlertSeverity"}, |
| 77 | + {Header: "STATUS", Field: "AlertStatus"}, |
| 78 | + {Header: "STARTED", Field: "StartTime"}, |
| 79 | + }, |
| 80 | + "AlertItem": { |
| 81 | + {Header: "ID", Field: "AlertID"}, |
| 82 | + {Header: "TITLE", Field: "Title", MaxWidth: 50}, |
| 83 | + {Header: "SEVERITY", Field: "AlertSeverity"}, |
| 84 | + {Header: "STATUS", Field: "AlertStatus"}, |
| 85 | + {Header: "EVENTS", Field: "EventCnt"}, |
| 86 | + {Header: "CHANNEL", Field: "ChannelName"}, |
| 87 | + {Header: "STARTED", Field: "StartTime"}, |
| 88 | + }, |
| 89 | + "AlertEventItem": { |
| 90 | + {Header: "EVENT_ID", Field: "EventID"}, |
| 91 | + {Header: "ALERT_ID", Field: "AlertID"}, |
| 92 | + {Header: "SEVERITY", Field: "EventSeverity"}, |
| 93 | + {Header: "STATUS", Field: "EventStatus"}, |
| 94 | + {Header: "TIME", Field: "EventTime"}, |
| 95 | + {Header: "TITLE", Field: "Title", MaxWidth: 50}, |
| 96 | + }, |
| 97 | + "ChangeItem": { |
| 98 | + {Header: "ID", Field: "ChangeID"}, |
| 99 | + {Header: "TITLE", Field: "Title", MaxWidth: 50}, |
| 100 | + {Header: "STATUS", Field: "ChangeStatus"}, |
| 101 | + {Header: "CHANNEL", Field: "ChannelName"}, |
| 102 | + {Header: "TIME", Field: "StartTime"}, |
| 103 | + }, |
| 104 | + "ChannelItem": { |
| 105 | + {Header: "ID", Field: "ChannelID"}, |
| 106 | + {Header: "NAME", Field: "ChannelName", MaxWidth: 40}, |
| 107 | + {Header: "TEAM_ID", Field: "TeamID"}, |
| 108 | + {Header: "CREATOR_ID", Field: "CreatorID"}, |
| 109 | + {Header: "STATUS", Field: "Status"}, |
| 110 | + }, |
| 111 | + "TeamItem": { |
| 112 | + {Header: "ID", Field: "TeamID"}, |
| 113 | + {Header: "NAME", Field: "TeamName", MaxWidth: 40}, |
| 114 | + }, |
| 115 | + "MemberItem": { |
| 116 | + {Header: "ID", Field: "MemberID"}, |
| 117 | + {Header: "NAME", Field: "MemberName", MaxWidth: 30}, |
| 118 | + {Header: "EMAIL", Field: "Email"}, |
| 119 | + {Header: "STATUS", Field: "Status"}, |
| 120 | + {Header: "TIMEZONE", Field: "TimeZone"}, |
| 121 | + }, |
| 122 | + "FieldItem": { |
| 123 | + {Header: "ID", Field: "FieldID"}, |
| 124 | + {Header: "NAME", Field: "FieldName"}, |
| 125 | + {Header: "DISPLAY_NAME", Field: "DisplayName"}, |
| 126 | + {Header: "TYPE", Field: "FieldType"}, |
| 127 | + }, |
| 128 | + "WarRoomItem": { |
| 129 | + {Header: "INTEGRATION", Field: "IntegrationID"}, |
| 130 | + {Header: "CHAT_ID", Field: "ChatID"}, |
| 131 | + {Header: "INCIDENT_ID", Field: "IncidentID"}, |
| 132 | + {Header: "STATUS", Field: "Status"}, |
| 133 | + {Header: "PLUGIN", Field: "PluginType"}, |
| 134 | + {Header: "CREATED", Field: "CreatedAt"}, |
| 135 | + }, |
| 136 | + "WarRoomPersonItem": { |
| 137 | + {Header: "PERSON_ID", Field: "PersonID"}, |
| 138 | + {Header: "NAME", Field: "PersonName"}, |
| 139 | + {Header: "EMAIL", Field: "Email"}, |
| 140 | + {Header: "STATUS", Field: "Status"}, |
| 141 | + }, |
| 142 | + // DimensionInsightItem backs both `insight team` and `insight channel` (same |
| 143 | + // Go type, different populated name field) — show both name columns, the |
| 144 | + // irrelevant one renders empty. Columns mirror the curated insight tables. |
| 145 | + "DimensionInsightItem": { |
| 146 | + {Header: "TEAM", Field: "TeamName", MaxWidth: 30}, |
| 147 | + {Header: "CHANNEL", Field: "ChannelName", MaxWidth: 30}, |
| 148 | + {Header: "INCIDENTS", Field: "TotalIncidentCnt"}, |
| 149 | + {Header: "ACK%", Field: "AcknowledgementPct", Format: fmtPercent}, |
| 150 | + {Header: "MTTA", Field: "MeanSecondsToAck", Format: fmtSecondsDuration}, |
| 151 | + {Header: "MTTR", Field: "MeanSecondsToClose", Format: fmtSecondsDuration}, |
| 152 | + {Header: "NOISE_REDUCTION", Field: "NoiseReductionPct", Format: fmtPercent}, |
| 153 | + {Header: "ALERTS", Field: "TotalAlertCnt"}, |
| 154 | + {Header: "EVENTS", Field: "TotalAlertEventCnt"}, |
| 155 | + }, |
| 156 | + "ResponderInsightItem": { |
| 157 | + {Header: "RESPONDER", Field: "ResponderName", MaxWidth: 30}, |
| 158 | + {Header: "INCIDENTS", Field: "TotalIncidentCnt"}, |
| 159 | + {Header: "ACK%", Field: "AcknowledgementPct", Format: fmtPercent}, |
| 160 | + {Header: "MTTA", Field: "MeanSecondsToAck", Format: fmtSecondsDuration}, |
| 161 | + {Header: "INTERRUPTIONS", Field: "TotalInterruptions"}, |
| 162 | + {Header: "ENGAGED", Field: "TotalEngagedSeconds", Format: fmtSecondsDuration}, |
| 163 | + }, |
| 164 | +} |
0 commit comments