1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
// SPDX-License-Identifier: GPL-3.0-only
//! Coverage CLI shell — thin command-tier wrapper over the coverage engine
//! modules (`coverage_store`, `coverage_verify`, `coverage_view`).
use std::str::FromStr;
use anyhow::Result;
use clap::Subcommand;
use crate::coverage_store;
use crate::coverage_verify;
use crate::coverage_view;
use crate::listing::Format;
#[derive(Subcommand)]
pub(crate) enum CoverageCommand {
/// Show requirement coverage and drift.
/// `<reference>` is REQ-NNN (one row) or PRD-/SPEC-NNN (a member fan).
/// Derived observed coverage + the drift verdict against authored status —
/// never writes, never derives status.
Show {
/// Canonical ref: REQ-NNN | PRD-NNN | SPEC-NNN.
reference: String,
/// Select/order visible table columns (e.g. `--columns id,status,verdict`).
#[arg(long, value_delimiter = ',')]
columns: Option<Vec<String>>,
/// Output format (table | json).
#[arg(long, value_parser = Format::from_str, default_value_t = Format::Table)]
format: Format,
/// Shorthand for `--format json`.
#[arg(long)]
json: bool,
/// Explicit project root (default: auto-detect).
#[arg(short = 'p', long)]
path: Option<std::path::PathBuf>,
},
/// Record a coverage observation.
/// With any check field the cell is a `VT` recipe (leans Planned until
/// verified); with none it is a `VA`/`VH` attestation.
Record {
/// Slice the cell is recorded under — `SL-NNN` or the bare number.
#[arg(long)]
slice: String,
/// The requirement this evidence covers — `REQ-NNN`.
#[arg(long)]
requirement: String,
/// The contributing change — `SL-NNN` (often the same as `--slice`).
#[arg(long)]
change: String,
/// Verification mode: `VT` | `VA` | `VH`.
#[arg(long)]
mode: String,
/// Observed status for a `VA`/`VH` attestation (default: verified). Ignored
/// for a `VT` record (the verifier derives it; it leans Planned at record).
#[arg(long, value_parser = coverage_store::parse_status)]
status: Option<crate::requirement::CoverageStatus>,
/// VT-check alias into `[verification.aliases]` (XOR `--command`).
#[arg(long)]
alias: Option<String>,
/// VT-check literal command argv, repeatable (XOR `--alias`).
#[arg(long = "command")]
command: Vec<String>,
/// Extra args appended to the resolved base argv, repeatable.
#[arg(long = "extra-args")]
extra_args: Vec<String>,
/// Matcher source: `stdout` | `stderr` | `file:<glob>`.
#[arg(long = "matcher-source")]
matcher_source: Option<String>,
/// Matcher pattern (substring, or regex with `--regex`).
#[arg(long = "matcher-pattern")]
matcher_pattern: Option<String>,
/// Treat `--matcher-pattern` as a `regex_lite` pattern.
#[arg(long)]
regex: bool,
/// Attestation date override (`YYYY-MM-DD`) for `VA`/`VH` (default: today).
#[arg(long = "attested-date")]
attested_date: Option<String>,
/// Explicit project root (default: auto-detect).
#[arg(short = 'p', long)]
path: Option<std::path::PathBuf>,
},
/// Re-derive `VT` coverage status by re-running each entry's check. A single
/// `<slice>` re-derives that slice; `--all` re-derives every slice (the
/// global-dedup set — a shared check runs once across the invocation).
Verify {
/// The slice to verify — `SL-NNN` or the bare number (omit with `--all`).
slice: Option<String>,
/// Verify every slice in the corpus.
#[arg(long)]
all: bool,
/// Explicit project root (default: auto-detect).
#[arg(short = 'p', long)]
path: Option<std::path::PathBuf>,
},
/// Erase one coverage cell (the 4-tuple key) from a slice's store. Prints the
/// withdrawn cell — a deletion that flips a composite green is never silent.
Forget {
/// Slice the cell lives under — `SL-NNN` or the bare number.
#[arg(long)]
slice: String,
/// The requirement the cell covers — `REQ-NNN`.
#[arg(long)]
requirement: String,
/// The contributing change — `SL-NNN`.
#[arg(long)]
change: String,
/// Verification mode: `VT` | `VA` | `VH`.
#[arg(long)]
mode: String,
/// Explicit project root (default: auto-detect).
#[arg(short = 'p', long)]
path: Option<std::path::PathBuf>,
},
}
pub(crate) fn dispatch(cmd: CoverageCommand, color: bool) -> Result<()> {
match cmd {
CoverageCommand::Show {
reference,
columns,
format,
json,
path,
} => coverage_view::run(path, &reference, columns.as_deref(), format, json, color),
CoverageCommand::Record {
slice,
requirement,
change,
mode,
status,
alias,
command,
extra_args,
matcher_source,
matcher_pattern,
regex,
attested_date,
path,
} => coverage_store::run_record(
path,
&coverage_store::CoverageRecordArgs {
slice: &slice,
requirement: &requirement,
change: &change,
mode: &mode,
status,
alias: alias.as_deref(),
command: &command,
extra_args: &extra_args,
matcher_source: matcher_source.as_deref(),
matcher_pattern: matcher_pattern.as_deref(),
regex,
attested_date: attested_date.as_deref(),
},
),
CoverageCommand::Verify { slice, all, path } => {
coverage_verify::run_cli(path, slice.as_deref(), all)
}
CoverageCommand::Forget {
slice,
requirement,
change,
mode,
path,
} => coverage_store::run_forget(path, &slice, &requirement, &change, &mode),
}
}