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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
//! CLI argument parsing
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "odm")]
#[command(about = "An odd document manager", long_about = None)]
#[command(version)]
#[command(after_help = "Use 'odm <command> --help' for more information about a command.")]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
/// Path to docs directory (defaults to ./docs)
#[arg(short, long, default_value = "docs")]
pub docs_dir: String,
}
#[derive(Subcommand)]
pub enum DebugCommands {
/// Show state information
State {
/// Document number (optional, shows all if omitted)
number: Option<u32>,
/// Output format (json, table, summary)
#[arg(short, long, default_value = "table")]
format: String,
},
/// Show checksums and dirty files
Checksums {
/// Show all files, not just dirty ones
#[arg(short, long)]
verbose: bool,
},
/// Show repository statistics
Stats,
/// Show diff between state and filesystem
Diff,
/// Show orphaned entries
Orphans,
/// Verify a specific document
Verify {
/// Document number
number: u32,
},
}
#[derive(Subcommand)]
#[command(next_display_order = None)] // Enable alphabetical sorting in help output
pub enum Commands {
/// List all design documents
#[command(visible_alias = "ls")]
List {
/// Filter by state (draft, under-review, revised, accepted, active, final, deferred, rejected, withdrawn, superseded)
#[arg(short, long)]
state: Option<String>,
/// Show full details
#[arg(short, long)]
verbose: bool,
/// Show only removed documents
#[arg(long)]
removed: bool,
/// Show untracked development documents
#[arg(long)]
dev: bool,
/// Filter by component
#[arg(short, long)]
component: Option<String>,
/// Filter by tags (comma-separated, matches ANY tag)
#[arg(short, long, value_delimiter = ',')]
tags: Vec<String>,
/// Maximum number of documents to display per table (default: 20)
#[arg(short, long, default_value = "20")]
limit: usize,
/// Show all documents (no limit)
#[arg(long)]
all: bool,
},
/// Show a specific document
Show {
/// Document number
number: u32,
/// Show only metadata
#[arg(short, long)]
metadata_only: bool,
},
/// Create a new design document
New {
/// Document title
title: String,
/// Author name (defaults to git config user.name)
#[arg(short, long)]
author: Option<String>,
/// System component (e.g., Compiler, AST, REPL, Tooling)
#[arg(short, long)]
component: Option<String>,
/// Tags (comma-separated, e.g., "Phase-0,Research,Protocol")
#[arg(short, long, value_delimiter = ',')]
tags: Vec<String>,
},
/// Validate all documents
#[command(visible_alias = "check")]
Validate {
/// Fix issues automatically where possible
#[arg(short, long)]
fix: bool,
},
/// Generate the index file
#[command(visible_alias = "gen-index")]
Index {
/// Output format (markdown or json)
#[arg(short, long, default_value = "markdown")]
format: String,
},
/// Add or update YAML frontmatter headers
#[command(visible_alias = "headers")]
AddHeaders {
/// Path to document
path: String,
},
/// Transition document to a new state
#[command(visible_alias = "mv")]
Transition {
/// Path to document
path: String,
/// New state (draft, under-review, revised, accepted, active, final, deferred, rejected, withdrawn, superseded)
state: String,
},
/// Move document to directory matching its state header
#[command(visible_alias = "sync")]
SyncLocation {
/// Path to document
path: String,
},
/// Synchronize the index with documents on filesystem
#[command(visible_alias = "sync-index")]
UpdateIndex,
/// Add a new document with full processing
Add {
/// Path to document file
path: String,
/// Initial state for the document (draft, accepted, active, etc.)
#[arg(short, long)]
state: Option<String>,
/// Show what would be done without making changes
#[arg(long)]
dry_run: bool,
/// Interactive mode (prompt for metadata)
#[arg(short, long)]
interactive: bool,
/// Auto-yes to prompts (non-interactive with defaults)
#[arg(short = 'y', long)]
yes: bool,
/// Show preview without making changes
#[arg(long)]
preview: bool,
},
/// Add multiple documents (supports glob patterns)
AddBatch {
/// File patterns (e.g., *.md, ~/docs/*.md)
patterns: Vec<String>,
/// Show what would be done without making changes
#[arg(long)]
dry_run: bool,
/// Interactive mode (confirm before adding)
#[arg(short, long)]
interactive: bool,
},
/// Scan filesystem and update document state
#[command(visible_alias = "rescan")]
Scan {
/// Fix issues automatically where possible
#[arg(short, long)]
fix: bool,
/// Show detailed validation output
#[arg(short, long)]
verbose: bool,
},
/// Debug and introspection commands
#[command(subcommand)]
Debug(DebugCommands),
/// Search documents
#[command(visible_alias = "grep")]
Search {
/// Search query
query: String,
/// Filter by state
#[arg(short, long)]
state: Option<String>,
/// Search only in metadata (YAML frontmatter)
#[arg(short, long)]
metadata: bool,
/// Case-sensitive search
#[arg(short = 'I', long)]
case_sensitive: bool,
},
/// Show tool information and documentation
Info {
/// Subcommand: states, fields, config, stats, dirs (optional, shows overview if omitted)
subcommand: Option<String>,
},
/// Remove a document (moves to dustbin)
#[command(visible_alias = "rm")]
Remove {
/// Document number or filename
doc: String,
},
/// Rename a document file (preserves number)
Rename {
/// Document number or file path to rename
old: String,
/// New file path
new: String,
},
/// Replace a document while preserving its ID
Replace {
/// Document number or filename to replace
old: String,
/// New document file path
new: String,
/// Set version explicitly (default: auto-increment minor version)
#[arg(short = 'V', long)]
version: Option<String>,
},
}