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
//! Top-level clap subcommand enum.
//!
//! This module owns command names, aliases, and subcommand argument wiring. The
//! execution dispatcher remains in `crate::commands`.
use clap::Subcommand;
use super::{
BadgeArgs, BaselineArgs, CliAnalyzeArgs, CliCheckIgnoreArgs, CliContextArgs, CliExportArgs,
CliGateArgs, CliLangArgs, CliModuleArgs, CockpitArgs, CompletionsArgs, DiffArgs,
EvidencePacketArgs, HandoffArgs, InitArgs, PacketArgs, RenderArgs, RunArgs, SensorArgs,
ToolsArgs,
};
#[cfg(feature = "ast")]
use super::SyntaxArgs;
#[derive(Subcommand, Debug, Clone)]
pub enum Commands {
/// Language summary (default).
Lang(CliLangArgs),
/// Module summary (group by path prefixes like `crates/<name>` or `packages/<name>`).
Module(CliModuleArgs),
/// Export a file-level dataset (CSV / JSONL / JSON).
Export(CliExportArgs),
/// Analyze receipts or paths to produce derived metrics.
#[command(visible_alias = "analyse")]
Analyze(CliAnalyzeArgs),
/// Render a simple SVG badge for a metric.
Badge(BadgeArgs),
/// Write a `.tokeignore` template to the target directory.
Init(InitArgs),
/// Generate shell completions.
#[command(visible_alias = "completion")]
Completions(CompletionsArgs),
/// Run a full scan and save receipts to a state directory.
Run(RunArgs),
/// Compare two receipts or runs.
Diff(DiffArgs),
/// Pack files into an LLM context window within a token budget.
Context(CliContextArgs),
/// Check why a file is being ignored (for troubleshooting).
CheckIgnore(CliCheckIgnoreArgs),
/// Output CLI schema as JSON for AI agents.
Tools(ToolsArgs),
/// Evaluate policy rules against analysis receipts.
Gate(CliGateArgs),
/// Generate PR cockpit metrics for code review.
Cockpit(CockpitArgs),
/// Generate a complexity baseline for trend tracking.
Baseline(BaselineArgs),
/// Bundle codebase for LLM handoff.
Handoff(HandoffArgs),
/// Run as a conforming sensor, producing a SensorReport.
Sensor(SensorArgs),
/// Emit feature-gated Tree-sitter syntax receipts.
#[cfg(feature = "ast")]
Syntax(SyntaxArgs),
/// Write a scoped evidence packet manifest.
EvidencePacket(EvidencePacketArgs),
/// Generate evidence packets over the existing receipt commands.
Packet(PacketArgs),
/// Render audience-specific Markdown from cross-tool packet bundles.
Render(RenderArgs),
}
#[cfg(test)]
mod tests {
use clap::Parser;
use super::*;
use crate::cli::parser::Cli;
#[test]
fn depth_visible_alias_sets_module_depth_for_module_like_commands() {
let cli = Cli::try_parse_from(["tokmd", "module", "--depth", "3"]).unwrap();
match cli.command.unwrap() {
Commands::Module(args) => assert_eq!(args.module_depth, Some(3)),
other => panic!("unexpected command: {other:?}"),
}
let cli = Cli::try_parse_from(["tokmd", "export", "--depth", "3"]).unwrap();
match cli.command.unwrap() {
Commands::Export(args) => assert_eq!(args.module_depth, Some(3)),
other => panic!("unexpected command: {other:?}"),
}
let cli = Cli::try_parse_from(["tokmd", "context", "--depth", "3"]).unwrap();
match cli.command.unwrap() {
Commands::Context(args) => assert_eq!(args.module_depth, Some(3)),
other => panic!("unexpected command: {other:?}"),
}
let cli = Cli::try_parse_from(["tokmd", "handoff", "--depth", "3"]).unwrap();
match cli.command.unwrap() {
Commands::Handoff(args) => assert_eq!(args.module_depth, Some(3)),
other => panic!("unexpected command: {other:?}"),
}
}
}