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
//! Command-line interface definition (clap derive).
use std::path::PathBuf;
use clap::{Parser, Subcommand};
use crate::format::Format;
#[derive(Parser, Debug)]
#[command(
name = "redink",
version,
about = "A spellchecker for prose — a TUI for humans, a JSON CLI for agents"
)]
pub struct Cli {
#[command(flatten)]
pub opts: GlobalOpts,
/// Files to check with no subcommand given (launches the TUI when
/// interactive, otherwise a non-interactive check). With none given, walks
/// the current directory for text/markdown.
#[arg(value_name = "FILES")]
pub files: Vec<PathBuf>,
#[command(subcommand)]
pub command: Option<Command>,
}
#[derive(clap::Args, Debug)]
pub struct GlobalOpts {
/// Override the working-dictionary path (default: nearest `.redink.dic`).
#[arg(long, global = true)]
pub dict: Option<PathBuf>,
/// Dictionary language, e.g. en_US, en_GB (default: en_US).
#[arg(long, global = true, default_value = "en_US")]
pub lang: String,
/// Directory containing `<lang>.aff` / `<lang>.dic` (otherwise searched).
#[arg(long, global = true)]
pub sysdict_dir: Option<PathBuf>,
/// Input format for files without a recognizable extension.
#[arg(long, global = true, value_enum, default_value_t = Format::Auto)]
pub format: Format,
/// Disregard in-file `<!-- redink:... -->` directives: check `off`/`on`
/// regions and drop `allow` lists. For auditing what they hide.
#[arg(long, global = true)]
pub no_ignore: bool,
}
impl GlobalOpts {
/// How sources are read, per these options.
pub fn source(&self) -> crate::format::Options {
crate::format::Options {
format: self.format,
directives: !self.no_ignore,
}
}
}
#[derive(Subcommand, Debug)]
pub enum Command {
/// Non-interactive check. Prints results to stdout.
Check {
/// Files to check. With none, walks the cwd for text/markdown.
files: Vec<PathBuf>,
/// Emit JSON (one object per occurrence) for programmatic use.
#[arg(long)]
json: bool,
/// Print only unique misspelled words, one per line.
#[arg(long)]
words: bool,
},
/// Interactive terminal UI (list + detail, with suggestions).
Tui {
/// Files to check. With none, walks the cwd for text/markdown.
files: Vec<PathBuf>,
},
/// Manage the working dictionary.
Dict {
#[command(subcommand)]
action: DictAction,
},
/// Replace the word at a byte offset (non-interactive; for agents).
Fix {
/// The file to edit in place.
file: PathBuf,
/// Absolute byte offset of the word to replace (see `check --json`).
#[arg(long)]
at: usize,
/// The word currently at that offset (validated before replacing).
#[arg(long)]
word: String,
/// The replacement text.
#[arg(long)]
to: String,
},
}
#[derive(Subcommand, Debug)]
pub enum DictAction {
/// List the words in the working dictionary.
List,
/// Add words or phrases. Case-insensitive by default; use --sensitive for
/// exact case (a multi-word argument then becomes an exact-case phrase).
Add {
words: Vec<String>,
#[arg(short = 's', long)]
sensitive: bool,
},
/// Remove words or phrases (matches either case layer).
Remove { words: Vec<String> },
}