linesmith 0.1.2

A Rust status line for Claude Code and other AI coding CLIs
Documentation
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
//! Command-line argument parsing via `lexopt`. Full flag surface and
//! rationale live in `docs/specs/config.md`.

use lexopt::prelude::*;
use std::ffi::OsString;
use std::path::PathBuf;

/// Parsed CLI arguments.
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct CliArgs {
    pub config: Option<PathBuf>,
    pub check_config: bool,
    pub color_override: Option<ColorOverride>,
}

/// User-supplied color-policy override. `--no-color` and `--force-color`
/// are mutually exclusive in intent; the flag that appears last on the
/// command line wins (lexopt assigns them in order).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum ColorOverride {
    Never,
    Always,
}

/// What the binary should do after parsing. `Run` is the common case;
/// every other variant is a meta-command that prints / writes and
/// exits.
#[derive(Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Action {
    Run(CliArgs),
    Help,
    Version,
    ThemesList,
    PresetsList,
    PresetsApply {
        name: String,
        force: bool,
        config: Option<PathBuf>,
    },
    Init {
        config: Option<PathBuf>,
        /// Skip the post-init `linesmith doctor` invocation.
        /// Per spec §`linesmith init` integration: doctor runs
        /// automatically after init writes the config; users
        /// pass `--no-doctor` to opt out (CI / scripted onboarding,
        /// or a host where doctor's network probe would block).
        no_doctor: bool,
    },
    // Intentionally absent from `HELP`: advertising "diagnose your
    // setup" while only emitting one PASS would be a false promise.
    // Re-list when build_report covers the full eight-category catalog
    // (see docs/specs/doctor.md §Check catalog).
    Doctor {
        plain: bool,
        config: Option<PathBuf>,
    },
}

/// Help text. Kept short; full docs live at
/// <https://github.com/oakoss/linesmith>.
pub const HELP: &str = "\
linesmith — status line for Claude Code and other AI coding CLIs

USAGE:
    linesmith [OPTIONS]
    linesmith init [--no-doctor]
    linesmith doctor [--plain]
    linesmith themes list
    linesmith presets list
    linesmith presets apply <NAME> [--force]

OPTIONS:
    -c, --config <PATH>    Config file path (overrides default resolution)
        --check-config     Validate config and exit
        --no-color         Strip all color (equivalent to NO_COLOR=1)
        --force-color      Emit color even in non-TTY output
        --force            For `presets apply`: overwrite without confirmation
        --no-doctor        For `init`: skip the post-init doctor run
        --plain            For `doctor`: ASCII output (no Unicode glyphs)
    -h, --help             Print this help text
    -V, --version          Print version

SUBCOMMANDS:
    init                   Interactive onboarding: pick a preset + theme,
                           write config.toml, print Claude Code snippet,
                           and run a setup-verification check (`--no-doctor`
                           to skip)
    doctor                 Run setup diagnostics (env, config, Claude Code
                           integration, credentials, cache, plugins, git);
                           exits 1 on any FAIL
    themes list            List available themes (built-in + user)
    presets list           List available config presets
    presets apply <NAME>   Write a preset's config.toml to the resolved path

Reads a statusline JSON payload on stdin; writes the rendered line to
stdout. See docs/specs/input-schema.md for the payload contract.
";

/// Parse an iterator of raw arguments. Pure: callers pass
/// `std::env::args_os().skip(1)` at startup and tests pass literals.
pub fn parse<I>(raw: I) -> Result<Action, lexopt::Error>
where
    I: IntoIterator,
    I::Item: Into<OsString>,
{
    let mut parser = lexopt::Parser::from_args(raw);
    let mut args = CliArgs::default();
    let mut positional: Vec<OsString> = Vec::new();
    let mut force = false;
    let mut plain = false;
    let mut no_doctor = false;
    while let Some(arg) = parser.next()? {
        match arg {
            Short('c') | Long("config") => {
                let value = parser.value()?;
                if value.is_empty() {
                    return Err(lexopt::Error::MissingValue {
                        option: Some("--config".to_string()),
                    });
                }
                args.config = Some(PathBuf::from(value));
            }
            Long("check-config") => {
                args.check_config = true;
            }
            Long("no-color") => {
                args.color_override = Some(ColorOverride::Never);
            }
            Long("force-color") => {
                args.color_override = Some(ColorOverride::Always);
            }
            Long("force") => {
                // Today `--force` is a `presets apply` modifier hoisted
                // to top-level parsing. If a second subcommand-specific
                // flag lands (e.g. `presets show --plain`), rewrite
                // `dispatch_subcommand` to own its own parser slice
                // rather than growing parallel top-level bools.
                force = true;
            }
            Long("plain") => {
                plain = true;
            }
            Long("no-doctor") => {
                no_doctor = true;
            }
            Short('h') | Long("help") => return Ok(Action::Help),
            Short('V') | Long("version") => return Ok(Action::Version),
            Value(v) => positional.push(v),
            _ => return Err(arg.unexpected()),
        }
    }
    let color_override_snapshot = args.color_override;
    let action =
        match dispatch_subcommand(&positional, force, plain, no_doctor, args.config.clone())? {
            Some(action) => action,
            None => Action::Run(args),
        };
    // `--force` only has meaning under `presets apply`; accepting it
    // on any other action would encourage muscle-memory misuse.
    if force && !matches!(action, Action::PresetsApply { .. }) {
        return Err(lexopt::Error::UnexpectedOption("--force".to_string()));
    }
    // `--plain` only has meaning under `doctor`. Reject elsewhere so a
    // typo like `linesmith --plain themes list` doesn't silently no-op.
    if plain && !matches!(action, Action::Doctor { .. }) {
        return Err(lexopt::Error::UnexpectedOption("--plain".to_string()));
    }
    // `--no-doctor` only opts out of the post-`init` doctor run.
    // Accepting it on any other action would let a user pass
    // `--no-doctor doctor` (a doctor invocation that opts out of
    // itself) and other absurdities.
    if no_doctor && !matches!(action, Action::Init { .. }) {
        return Err(lexopt::Error::UnexpectedOption("--no-doctor".to_string()));
    }
    // Doctor renders without ANSI today (glyph alphabet + separator
    // are the only mode axes), so `--no-color` / `--force-color` would
    // be silent no-ops. Reject so a user piping doctor output through
    // a colorized log capture doesn't think they suppressed something
    // that was never there. Once doctor grows colored output, thread
    // the override through Action::Doctor at the same time.
    if matches!(action, Action::Doctor { .. }) {
        if let Some(override_) = color_override_snapshot {
            let flag = match override_ {
                ColorOverride::Never => "--no-color",
                ColorOverride::Always => "--force-color",
            };
            return Err(lexopt::Error::UnexpectedOption(flag.to_string()));
        }
    }
    Ok(action)
}

/// Recognize subcommands from positional args. Anything not matched
/// returns a clear error rather than silently falling through to `Run`.
fn dispatch_subcommand(
    positional: &[OsString],
    force: bool,
    plain: bool,
    no_doctor: bool,
    config: Option<PathBuf>,
) -> Result<Option<Action>, lexopt::Error> {
    if positional.is_empty() {
        return Ok(None);
    }
    let first = positional[0].to_string_lossy();
    match first.as_ref() {
        "init" => {
            if positional.len() > 1 {
                return Err(lexopt::Error::UnexpectedValue {
                    option: "init".to_string(),
                    value: positional[1].to_string_lossy().to_string().into(),
                });
            }
            Ok(Some(Action::Init { config, no_doctor }))
        }
        "doctor" => {
            if positional.len() > 1 {
                return Err(lexopt::Error::UnexpectedValue {
                    option: "doctor".to_string(),
                    value: positional[1].to_string_lossy().to_string().into(),
                });
            }
            Ok(Some(Action::Doctor { plain, config }))
        }
        "themes" => {
            let sub = positional.get(1).map(|s| s.to_string_lossy().into_owned());
            match sub.as_deref() {
                Some("list") if positional.len() == 2 => Ok(Some(Action::ThemesList)),
                Some(other) => Err(lexopt::Error::UnexpectedValue {
                    option: "themes".to_string(),
                    value: other.to_string().into(),
                }),
                None => Err(lexopt::Error::MissingValue {
                    option: Some("themes <subcommand>".to_string()),
                }),
            }
        }
        "presets" => {
            let sub = positional.get(1).map(|s| s.to_string_lossy().into_owned());
            match sub.as_deref() {
                Some("list") if positional.len() == 2 => Ok(Some(Action::PresetsList)),
                Some("apply") => {
                    let name = positional.get(2).ok_or(lexopt::Error::MissingValue {
                        option: Some("presets apply <NAME>".to_string()),
                    })?;
                    if positional.len() > 3 {
                        return Err(lexopt::Error::UnexpectedValue {
                            option: "presets apply".to_string(),
                            value: positional[3].to_string_lossy().to_string().into(),
                        });
                    }
                    Ok(Some(Action::PresetsApply {
                        name: name.to_string_lossy().into_owned(),
                        force,
                        config,
                    }))
                }
                Some(other) => Err(lexopt::Error::UnexpectedValue {
                    option: "presets".to_string(),
                    value: other.to_string().into(),
                }),
                None => Err(lexopt::Error::MissingValue {
                    option: Some("presets <subcommand>".to_string()),
                }),
            }
        }
        _ => Err(lexopt::Error::UnexpectedValue {
            option: "<subcommand>".to_string(),
            value: first.to_string().into(),
        }),
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    fn parse_args(args: &[&str]) -> Result<Action, lexopt::Error> {
        parse(args.iter().map(OsString::from))
    }

    #[test]
    fn empty_args_returns_run_with_defaults() {
        let got = parse_args(&[]).expect("ok");
        assert_eq!(got, Action::Run(CliArgs::default()));
    }

    #[test]
    fn help_short_and_long_return_help_action() {
        assert_eq!(parse_args(&["-h"]).expect("ok"), Action::Help);
        assert_eq!(parse_args(&["--help"]).expect("ok"), Action::Help);
    }

    #[test]
    fn version_short_and_long_return_version_action() {
        assert_eq!(parse_args(&["-V"]).expect("ok"), Action::Version);
        assert_eq!(parse_args(&["--version"]).expect("ok"), Action::Version);
    }

    #[test]
    fn config_flag_captures_path() {
        let got = parse_args(&["--config", "/etc/linesmith.toml"]).expect("ok");
        assert_eq!(
            got,
            Action::Run(CliArgs {
                config: Some(PathBuf::from("/etc/linesmith.toml")),
                check_config: false,
                color_override: None,
            })
        );
    }

    #[test]
    fn config_short_flag_captures_path() {
        let got = parse_args(&["-c", "/etc/linesmith.toml"]).expect("ok");
        assert_eq!(
            got,
            Action::Run(CliArgs {
                config: Some(PathBuf::from("/etc/linesmith.toml")),
                check_config: false,
                color_override: None,
            })
        );
    }

    #[test]
    fn check_config_flag_sets_bool() {
        let got = parse_args(&["--check-config"]).expect("ok");
        assert_eq!(
            got,
            Action::Run(CliArgs {
                config: None,
                check_config: true,
                color_override: None,
            })
        );
    }

    #[test]
    fn check_config_composes_with_config_path() {
        let got = parse_args(&["--config", "custom.toml", "--check-config"]).expect("ok");
        assert_eq!(
            got,
            Action::Run(CliArgs {
                config: Some(PathBuf::from("custom.toml")),
                check_config: true,
                color_override: None,
            })
        );
    }

    #[test]
    fn unknown_flag_returns_error() {
        let err = parse_args(&["--nope"]).unwrap_err();
        assert!(err.to_string().contains("nope"));
    }

    #[test]
    fn config_without_value_returns_error() {
        let err = parse_args(&["--config"]).unwrap_err();
        // Expected: lexopt surfaces a "missing value" flavor of error;
        // lock the variant rather than the specific wording.
        assert!(matches!(err, lexopt::Error::MissingValue { .. }));
    }

    #[test]
    fn empty_config_value_is_rejected() {
        // `--config ""` can happen from shell expansions like
        // `--config "$MAYBE_UNSET"`; reject rather than silently
        // falling through to defaults with no explanation.
        let err = parse_args(&["--config", ""]).unwrap_err();
        assert!(matches!(err, lexopt::Error::MissingValue { .. }));
    }

    #[test]
    fn no_color_flag_sets_never_override() {
        let got = parse_args(&["--no-color"]).expect("ok");
        assert_eq!(
            got,
            Action::Run(CliArgs {
                config: None,
                check_config: false,
                color_override: Some(ColorOverride::Never),
            })
        );
    }

    #[test]
    fn force_color_flag_sets_always_override() {
        let got = parse_args(&["--force-color"]).expect("ok");
        assert_eq!(
            got,
            Action::Run(CliArgs {
                config: None,
                check_config: false,
                color_override: Some(ColorOverride::Always),
            })
        );
    }

    #[test]
    fn conflicting_color_flags_last_wins() {
        // lexopt assigns in order; last flag on the command line wins.
        // Users don't get an error when both flags appear — they get
        // the most recently specified intent.
        let got = parse_args(&["--no-color", "--force-color"]).expect("ok");
        match got {
            Action::Run(args) => assert_eq!(args.color_override, Some(ColorOverride::Always)),
            _ => panic!("expected Run action"),
        }
        let got = parse_args(&["--force-color", "--no-color"]).expect("ok");
        match got {
            Action::Run(args) => assert_eq!(args.color_override, Some(ColorOverride::Never)),
            _ => panic!("expected Run action"),
        }
    }

    #[test]
    fn themes_list_subcommand_parses() {
        assert_eq!(
            parse_args(&["themes", "list"]).expect("ok"),
            Action::ThemesList
        );
    }

    #[test]
    fn themes_without_subcommand_errors() {
        let err = parse_args(&["themes"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::MissingValue { .. }));
    }

    #[test]
    fn themes_with_unknown_subcommand_errors() {
        let err = parse_args(&["themes", "remove"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::UnexpectedValue { .. }));
    }

    #[test]
    fn unknown_top_level_subcommand_errors() {
        let err = parse_args(&["bogus"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::UnexpectedValue { .. }));
    }

    #[test]
    fn presets_list_subcommand_parses() {
        assert_eq!(
            parse_args(&["presets", "list"]).expect("ok"),
            Action::PresetsList
        );
    }

    #[test]
    fn presets_apply_subcommand_parses_name() {
        assert_eq!(
            parse_args(&["presets", "apply", "developer"]).expect("ok"),
            Action::PresetsApply {
                name: "developer".to_string(),
                force: false,
                config: None,
            }
        );
    }

    #[test]
    fn presets_apply_with_force_flag_sets_force() {
        let got = parse_args(&["presets", "apply", "developer", "--force"]).expect("ok");
        assert_eq!(
            got,
            Action::PresetsApply {
                name: "developer".to_string(),
                force: true,
                config: None,
            }
        );
    }

    #[test]
    fn presets_apply_without_name_errors() {
        let err = parse_args(&["presets", "apply"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::MissingValue { .. }));
    }

    #[test]
    fn presets_apply_with_extra_positional_errors() {
        let err = parse_args(&["presets", "apply", "developer", "extra"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::UnexpectedValue { .. }));
    }

    #[test]
    fn presets_without_subcommand_errors() {
        let err = parse_args(&["presets"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::MissingValue { .. }));
    }

    #[test]
    fn presets_with_unknown_subcommand_errors() {
        let err = parse_args(&["presets", "delete", "minimal"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::UnexpectedValue { .. }));
    }

    #[test]
    fn presets_apply_force_before_subcommand_also_parses() {
        // lexopt interleaves flags and positionals; pinning both
        // orderings prevents a parser regression that accepts only one.
        let got = parse_args(&["--force", "presets", "apply", "developer"]).expect("ok");
        assert_eq!(
            got,
            Action::PresetsApply {
                name: "developer".to_string(),
                force: true,
                config: None,
            }
        );
    }

    #[test]
    fn force_flag_rejected_outside_presets_apply() {
        // `--force` only has meaning for `presets apply`; using it with
        // any other action should error rather than silently no-op.
        for args in [
            vec!["--force"],
            vec!["--force", "themes", "list"],
            vec!["--force", "presets", "list"],
            vec!["--force", "--check-config"],
        ] {
            let err = parse_args(&args).unwrap_err();
            assert!(
                matches!(err, lexopt::Error::UnexpectedOption(ref s) if s == "--force"),
                "args {args:?} should reject --force, got {err:?}"
            );
        }
    }

    #[test]
    fn presets_apply_threads_config_flag_into_action() {
        let got = parse_args(&[
            "--config",
            "/tmp/custom.toml",
            "presets",
            "apply",
            "minimal",
        ])
        .expect("ok");
        assert_eq!(
            got,
            Action::PresetsApply {
                name: "minimal".to_string(),
                force: false,
                config: Some(PathBuf::from("/tmp/custom.toml")),
            }
        );
    }

    #[test]
    fn presets_apply_empty_string_name_still_parses_as_apply() {
        // Driver will reject empty name via the registry lookup; CLI
        // only validates shape here.
        assert_eq!(
            parse_args(&["presets", "apply", ""]).expect("ok"),
            Action::PresetsApply {
                name: String::new(),
                force: false,
                config: None,
            }
        );
    }

    #[test]
    fn init_subcommand_parses_with_no_config_override() {
        assert_eq!(
            parse_args(&["init"]).expect("ok"),
            Action::Init {
                config: None,
                no_doctor: false,
            }
        );
    }

    #[test]
    fn init_threads_config_flag_into_action() {
        let got = parse_args(&["--config", "/tmp/init.toml", "init"]).expect("ok");
        assert_eq!(
            got,
            Action::Init {
                config: Some(PathBuf::from("/tmp/init.toml")),
                no_doctor: false,
            }
        );
    }

    #[test]
    fn init_no_doctor_flag_sets_field() {
        assert_eq!(
            parse_args(&["init", "--no-doctor"]).expect("ok"),
            Action::Init {
                config: None,
                no_doctor: true,
            }
        );
    }

    #[test]
    fn init_no_doctor_before_subcommand_also_parses() {
        // lexopt interleaves flags and positionals; pin both
        // orderings so a parser regression that rejects one
        // ordering trips here.
        assert_eq!(
            parse_args(&["--no-doctor", "init"]).expect("ok"),
            Action::Init {
                config: None,
                no_doctor: true,
            }
        );
    }

    #[test]
    fn no_doctor_flag_rejected_outside_init() {
        // `--no-doctor` only opts out of init's post-write doctor
        // run; using it elsewhere (`linesmith --no-doctor doctor`,
        // bare `--no-doctor`) should error rather than silently
        // no-op.
        for args in [
            vec!["--no-doctor"],
            vec!["--no-doctor", "doctor"],
            vec!["--no-doctor", "themes", "list"],
            vec!["--no-doctor", "presets", "list"],
        ] {
            let err = parse_args(&args).unwrap_err();
            assert!(
                matches!(err, lexopt::Error::UnexpectedOption(ref s) if s == "--no-doctor"),
                "args {args:?} should reject --no-doctor, got {err:?}",
            );
        }
    }

    #[test]
    fn init_with_extra_positional_errors() {
        let err = parse_args(&["init", "minimal"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::UnexpectedValue { .. }));
    }

    #[test]
    fn init_rejects_force_flag() {
        // `--force` is `presets apply`-only; init's overwrite path goes
        // through the same y/N prompt without a force escape hatch.
        let err = parse_args(&["--force", "init"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::UnexpectedOption(ref s) if s == "--force"));
    }

    #[test]
    fn doctor_subcommand_parses_with_no_flags() {
        assert_eq!(
            parse_args(&["doctor"]).expect("ok"),
            Action::Doctor {
                plain: false,
                config: None,
            }
        );
    }

    #[test]
    fn doctor_subcommand_parses_plain_flag() {
        assert_eq!(
            parse_args(&["doctor", "--plain"]).expect("ok"),
            Action::Doctor {
                plain: true,
                config: None,
            }
        );
    }

    #[test]
    fn doctor_plain_before_subcommand_also_parses() {
        // lexopt interleaves flags and positionals; pinning both
        // orderings prevents a parser regression that accepts only one.
        assert_eq!(
            parse_args(&["--plain", "doctor"]).expect("ok"),
            Action::Doctor {
                plain: true,
                config: None,
            }
        );
    }

    #[test]
    fn doctor_threads_config_flag_into_action() {
        // Without this, `linesmith doctor --config /tmp/alt.toml`
        // silently discarded the path and reported on the default
        // config instead of the file the user explicitly asked
        // about.
        let got = parse_args(&["--config", "/tmp/alt.toml", "doctor"]).expect("ok");
        assert_eq!(
            got,
            Action::Doctor {
                plain: false,
                config: Some(PathBuf::from("/tmp/alt.toml")),
            }
        );
    }

    #[test]
    fn color_overrides_rejected_on_doctor() {
        // Doctor renders without ANSI today; honoring --no-color /
        // --force-color silently would let a user think they
        // suppressed something that was never there. Reject at parse
        // time. When doctor gains color, thread the override into
        // Action::Doctor and remove this rejection.
        for (flag, expected) in [
            ("--no-color", "--no-color"),
            ("--force-color", "--force-color"),
        ] {
            let err = parse_args(&[flag, "doctor"]).unwrap_err();
            assert!(
                matches!(err, lexopt::Error::UnexpectedOption(ref s) if s == expected),
                "flag {flag} should be rejected on doctor, got {err:?}"
            );
        }
    }

    #[test]
    fn doctor_combines_config_and_plain() {
        let got = parse_args(&["--config", "/tmp/alt.toml", "doctor", "--plain"]).expect("ok");
        assert_eq!(
            got,
            Action::Doctor {
                plain: true,
                config: Some(PathBuf::from("/tmp/alt.toml")),
            }
        );
    }

    #[test]
    fn doctor_with_extra_positional_errors() {
        let err = parse_args(&["doctor", "extra"]).unwrap_err();
        assert!(matches!(err, lexopt::Error::UnexpectedValue { .. }));
    }

    #[test]
    fn plain_flag_rejected_outside_doctor() {
        // Mirror the surface coverage that `--force` gets so a typo
        // like `linesmith --plain themes list` doesn't silently no-op.
        for args in [
            vec!["--plain"],
            vec!["--plain", "themes", "list"],
            vec!["--plain", "presets", "list"],
            vec!["--plain", "presets", "apply", "minimal"],
            vec!["--plain", "init"],
            vec!["--plain", "--check-config"],
        ] {
            let err = parse_args(&args).unwrap_err();
            assert!(
                matches!(err, lexopt::Error::UnexpectedOption(ref s) if s == "--plain"),
                "args {args:?} should reject --plain, got {err:?}"
            );
        }
    }

    #[test]
    fn equals_style_config_value_parses() {
        // lexopt supports `--config=PATH`; pin so a parser swap
        // doesn't silently drop the shape users will try.
        let got = parse_args(&["--config=/custom.toml"]).expect("ok");
        assert_eq!(
            got,
            Action::Run(CliArgs {
                config: Some(PathBuf::from("/custom.toml")),
                check_config: false,
                color_override: None,
            })
        );
    }
}