Skip to main content

tess/
cli.rs

1use std::path::PathBuf;
2use clap::Parser;
3use clap::builder::styling::{AnsiColor, Color, Style};
4use clap::builder::Styles;
5
6const HELP_STYLES: Styles = Styles::styled()
7    .header(Style::new().bold().fg_color(Some(Color::Ansi(AnsiColor::Yellow))))
8    .usage(Style::new().bold().fg_color(Some(Color::Ansi(AnsiColor::Yellow))))
9    .literal(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan))))
10    .placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::Cyan))));
11
12#[derive(Parser, Debug, Clone)]
13#[command(name = "tess", version, about = "A less-style terminal pager.", styles = HELP_STYLES)]
14pub struct Args {
15    /// Render images with Unicode half-blocks (▀, fg=top pixel, bg=bottom
16    /// pixel) for ~2× vertical detail instead of the default character ramp.
17    #[arg(long = "blocks")]
18    pub blocks: bool,
19
20    /// Chop long lines instead of wrapping.
21    #[arg(short = 'S', long = "chop-long-lines")]
22    pub chop: bool,
23
24    /// Collapse runs of two or more consecutive blank lines into a
25    /// single blank line at display time. Real line numbers, search,
26    /// and tag jumps are unaffected (they reference the original
27    /// count). Mirrors `less -s`.
28    #[arg(short = 's', long = "squeeze-blank-lines")]
29    pub squeeze_blanks: bool,
30
31    /// Pin the top L source lines (and the left C columns, when
32    /// horizontal scroll is supported) at the top of the viewport.
33    /// Form: `L` or `L,C`. Default `0,0` (off). Mirrors `less --header`.
34    /// Runtime adjustment: `:header L [C]`.
35    #[arg(long = "header", value_name = "L[,C]")]
36    pub header: Option<String>,
37
38    /// Character to show at the right edge of a chopped line (`-S` chop
39    /// mode) indicating "more content right". Default `>`. Pass an empty
40    /// string to disable. Mirrors `less --rscroll=c`.
41    #[arg(long = "rscroll", value_name = "CHAR", default_value = ">")]
42    pub rscroll: String,
43
44    /// PageDown / PageUp step size in lines. Default: full screen
45    /// height (body rows). Half-page commands always advance by half
46    /// the screen regardless. Mirrors `less -zn` / `--window=n`.
47    #[arg(short = 'z', long = "window", value_name = "N")]
48    pub window: Option<u16>,
49
50    /// In wrap mode, break lines on whitespace boundaries instead of
51    /// mid-character when possible. Falls back to mid-character break
52    /// when no whitespace fits in the row. Mirrors `less --wordwrap`.
53    #[arg(long = "wordwrap")]
54    pub word_wrap: bool,
55
56    /// Follow the file by path rather than by descriptor (matches
57    /// `tail -F` / `less --follow-name`). `tess` already does this —
58    /// rotation and truncation are detected on every poll and the
59    /// source re-opens by path (since 0.25.0). This flag is accepted
60    /// for compatibility and currently has no behavioral effect.
61    #[arg(long = "follow-name")]
62    pub follow_name: bool,
63
64    /// In follow mode with piped stdin, exit when the upstream writer
65    /// closes the pipe. Default behavior (off): tess remains open on
66    /// the captured content after stdin EOF. Mirrors
67    /// `less --exit-follow-on-close`.
68    #[arg(long = "exit-follow-on-close")]
69    pub exit_follow_on_close: bool,
70
71    /// Force the content type for `--prettify` (otherwise auto-detected from
72    /// the filename extension and the first bytes). Values:
73    /// `auto`, `raw`, `json`, `yaml`, `toml`, `xml`, `html`, `csv`.
74    /// Setting this implies `--prettify` (unless the value is `raw`/`auto`).
75    #[arg(long = "content-type", value_name = "TYPE")]
76    pub content_type: Option<String>,
77
78    /// With `--filter`, dim non-matching lines instead of hiding them. Keeps
79    /// surrounding context visible.
80    #[arg(long = "dim")]
81    pub dim: bool,
82
83    /// Render each parsed line through this template instead of showing the
84    /// raw line. Syntax: `<fieldname>` placeholders, `\<` for literal `<`,
85    /// `\\` for literal `\`. Example: `--display '[<time>] <status> <msg>'`.
86    /// Overrides the format's `display` key (if set). Requires `--format`.
87    /// Search still matches against the raw line.
88    #[arg(long = "display", value_name = "TEMPLATE")]
89    pub display: Option<String>,
90
91    /// Print a curated list of usage examples and exit.
92    #[arg(long = "examples")]
93    pub examples: bool,
94
95    /// Filter visible lines by parsed field. Repeatable; multiple filters AND.
96    /// Operators: `=` (exact), `!=` (exact ≠), `~` (regex), `!~` (regex ≠),
97    /// `<`, `<=`, `>`, `>=` (numeric if both sides parse as numbers, else
98    /// lexicographic). Examples: `--filter status=500`, `--filter ip~^10\.`,
99    /// `--filter 'status>=500'` (quote `<` and `>` to avoid shell redirection).
100    /// Requires `--format`.
101    #[arg(long = "filter", value_name = "FIELD<op>VALUE")]
102    pub filter: Vec<String>,
103
104    /// Follow mode: keep watching the source for new bytes (like `tail -f`).
105    /// Jumps to the bottom on startup. Toggle with Shift-F at runtime.
106    #[arg(short = 'f', long = "follow")]
107    pub follow: bool,
108
109    /// In follow mode, any user motion (scroll, page, goto-line) suspends
110    /// following. Re-engage with Shift-F. Default off: today's behavior
111    /// (movement keeps follow on; auto-scroll suspended while the viewport
112    /// is not at bottom). Matches `less +F` semantics when enabled.
113    #[arg(long = "follow-suspend-on-motion")]
114    pub follow_suspend_on_motion: bool,
115
116    /// Apply a named log format (built-in or user-defined in
117    /// ~/.config/tess/formats.toml). Required by `--filter`.
118    #[arg(long = "format", value_name = "NAME")]
119    pub format: Option<String>,
120
121    /// Filter visible lines by regex against the raw line. Repeatable;
122    /// multiple `--grep` arguments AND. Works on any input — no `--format`
123    /// required. Composes with `--filter` (both must match) and with
124    /// `--dim` (non-matches stay visible but faded).
125    /// Example: `--grep error --grep '^\['`.
126    #[arg(long = "grep", value_name = "PATTERN")]
127    pub grep: Vec<String>,
128
129    /// Smart-case search. `/`, `?`, `--grep`, and `--filter`'s `~` / `!~`
130    /// operators match case-insensitively unless the pattern contains an
131    /// uppercase character. Mirrors `less -i` / ripgrep / vim smartcase.
132    /// Mutually exclusive with `-I`. Runtime toggle: `:case`.
133    #[arg(short = 'i', long = "ignore-case", conflicts_with = "IGNORE_CASE")]
134    pub ignore_case: bool,
135
136    /// Force case-insensitive search regardless of pattern case. Mirrors
137    /// `less -I`. Mutually exclusive with `-i`.
138    #[arg(short = 'I', long = "IGNORE-CASE")]
139    #[allow(non_snake_case)]
140    pub IGNORE_CASE: bool,
141
142    /// Disable search-match highlighting by default. Search still
143    /// navigates (`n` / `N` jump to matches); the visual reverse-video
144    /// highlight is suppressed. Runtime toggle: `:hlsearch` / `:nohlsearch`.
145    /// Mirrors `less -G`.
146    #[arg(short = 'G', long = "no-hilite-search")]
147    pub no_hilite_search: bool,
148
149    /// Don't enter the alt-screen on startup. Content remains in
150    /// terminal scrollback after exit. Crucial for piped use and
151    /// debugging. Mirrors `less -X` / `--no-init`.
152    #[arg(short = 'X', long = "no-init")]
153    pub no_init: bool,
154
155    /// Exit immediately (without paging) if the entire source fits on
156    /// one screen. Ignored with piped stdin in follow mode. Mirrors
157    /// `less -F`.
158    #[arg(short = 'F', long = "quit-if-one-screen")]
159    pub quit_if_one_screen: bool,
160
161    /// Accepted for `less` compatibility. tess always exits on Ctrl-C
162    /// (Ctrl-C → Command::Quit in the input table), so this flag is a
163    /// no-op. Provided so existing `less` invocations work unchanged.
164    #[arg(short = 'K', long = "quit-on-intr")]
165    pub quit_on_intr: bool,
166
167    /// Quit when the user tries to scroll forward past end-of-file for
168    /// the second time. Mirrors `less -e`. Mutually exclusive with `-E`.
169    #[arg(short = 'e', long = "quit-at-eof", conflicts_with = "QUIT_AT_EOF")]
170    pub quit_at_eof: bool,
171
172    /// Quit the first time end-of-file is reached. Mirrors `less -E`.
173    #[arg(short = 'E', long = "QUIT-AT-EOF")]
174    #[allow(non_snake_case)]
175    pub QUIT_AT_EOF: bool,
176
177    /// Show only the first N lines of the source. Mutually exclusive with --tail.
178    #[arg(long = "head", value_name = "N", conflicts_with = "tail")]
179    pub head: Option<usize>,
180
181    /// Render the source as an xxd-style hex dump instead of byte-faithful
182    /// text. 16 bytes per row, offset prefix, ASCII gutter. Mutually
183    /// exclusive with parsing- and rendering-oriented flags.
184    #[arg(
185        long = "hex",
186        conflicts_with_all = ["filter", "grep", "prettify", "format", "display", "record_start", "prompt", "preprocess"],
187    )]
188    pub hex: bool,
189
190    /// Hex characters per group in `--hex` mode. One of 2, 4, 8, 16, 32
191    /// (default 4, matching `xxd`). 32 means the whole row as a single
192    /// group with no spacing between hex pairs. Requires `--hex`. Can be
193    /// changed at runtime with `:hex N`.
194    #[arg(
195        long = "hex-group",
196        value_name = "N",
197        default_value_t = 4,
198        requires = "hex",
199    )]
200    pub hex_group: usize,
201
202    /// Target width in columns for image rendering. Defaults to the terminal
203    /// width interactively, or 80 when exporting to a file/stdout.
204    #[arg(long = "image-width", value_name = "N")]
205    pub image_width: Option<usize>,
206
207    /// Show line numbers.
208    #[arg(short = 'N', long = "LINE-NUMBERS")]
209    pub line_numbers: bool,
210
211    /// Print available log formats and their named fields, then exit.
212    #[arg(long = "list-formats")]
213    pub list_formats: bool,
214
215    /// Live mode: re-read the file when its on-disk content changes (mtime,
216    /// size, or inode). Use this for files rewritten in place — source files
217    /// being edited, files saved by an editor or AI agent. Different from
218    /// `--follow` (which watches for *appended* bytes); the two are mutually
219    /// exclusive. Press `R` inside the pager to force a reload.
220    #[arg(long = "live", conflicts_with = "follow")]
221    pub live: bool,
222
223    /// Print the full user manual and exit.
224    #[arg(long = "manual")]
225    pub manual: bool,
226
227    /// Enable mouse capture: click rows in the file picker / help overlay,
228    /// and scrollwheel scrolls the body. Trade-off: most terminals disable
229    /// their native text selection while mouse capture is on.
230    #[arg(long = "mouse")]
231    pub mouse: bool,
232
233    /// Show raw control bytes as `^X` glyphs (pre-0.18 default). Disables
234    /// SGR / OSC interpretation. Honoured also by the `NO_COLOR` environment
235    /// variable (any non-empty value) and `CLICOLOR=0`.
236    #[arg(long = "no-color")]
237    pub no_color: bool,
238
239    /// Treat a detected image file as raw/normal text instead of rendering it
240    /// as ASCII art. Has no effect on non-image inputs.
241    #[arg(long = "no-image")]
242    pub no_image: bool,
243
244    /// Ignore $LESSOPEN. Useful when LESSOPEN is exported but not wanted
245    /// for one invocation.
246    #[arg(long = "no-preprocess", conflicts_with = "preprocess")]
247    pub no_preprocess: bool,
248
249    /// Non-interactive batch mode: apply --filter / --grep / --head / --tail / --prettify
250    /// to the source and write the resulting raw bytes to FILE, then exit.
251    /// Use `-` for stdout (`--stdout` is a synonym). Skips the alt-screen and
252    /// raw mode entirely. With `--follow`, doesn't exit — keeps appending
253    /// matching new bytes to FILE as they arrive (Ctrl-C to stop). Not
254    /// compatible with `--live`.
255    #[arg(short = 'o', long = "output", value_name = "FILE")]
256    pub output: Option<String>,
257
258    /// Pipe the source file through this command before rendering.
259    /// Must start with `|`; `%s` is substituted with the file path.
260    /// Example: `--preprocess '|pdftotext %s -'`. Overrides $LESSOPEN.
261    #[arg(
262        long = "preprocess",
263        value_name = "CMD",
264        conflicts_with_all = ["no_preprocess", "hex", "follow", "live"],
265    )]
266    pub preprocess: Option<String>,
267
268    /// Pretty-print structured content (JSON, YAML, TOML, XML, HTML, CSV).
269    /// Detects the type from the filename extension or the first bytes; use
270    /// `--content-type=NAME` to override. Static files only — not allowed
271    /// with `--follow`, `--live`, or `--filter`. Toggle interactively with
272    /// `Shift-P`; force a type with `-P` then a letter (j/y/t/x/h/c).
273    #[arg(long = "prettify")]
274    pub prettify: bool,
275
276    /// Replace the hardcoded status format with a templated string.
277    /// Uses the same `<field>` syntax as `--display`. Available fields:
278    /// label, top, bottom, total, pct, rec-top, rec-bottom, rec-total,
279    /// rec-block, wrap-offset, format-tag, filter-tag, grep-tag,
280    /// hide-tag, search-tag, pretty-tag, live-tag, follow-tag.
281    /// Per-format default can be set via `prompt = '...'` in formats.toml.
282    /// Mutually exclusive with --hex.
283    #[arg(long = "prompt", value_name = "TEMPLATE", conflicts_with = "hex")]
284    pub prompt: Option<String>,
285
286    /// Pass every byte to the terminal raw, including cursor moves and
287    /// non-SGR escape sequences. Risky: scroll math may break on long lines.
288    /// Less-style -r. Mutually exclusive with --no-color.
289    #[arg(short = 'r', long = "raw-control-chars", conflicts_with = "no_color")]
290    pub raw_control_chars: bool,
291
292    /// Truecolor (24-bit RGB) handling. `auto` (default) checks `$COLORTERM`
293    /// and downsamples when truecolor isn't advertised; `never` always
294    /// downsamples to the 256-color palette; `always` passes RGB through
295    /// regardless of terminal capability.
296    #[arg(long = "truecolor", value_name = "MODE", default_value = "auto")]
297    pub truecolor: String,
298
299    /// Style for the status row. Comma-separated tokens: `bold`, `dim`,
300    /// `italic`, `underline`, `reverse`, `fg=COLOR`, `bg=COLOR`. COLOR is a
301    /// named color (`black`..`white`, optional `bright-` prefix), `#RRGGBB`,
302    /// or an indexed value (0–255). Empty string disables theming.
303    /// Default: `reverse`.
304    #[arg(long = "status-style", value_name = "SPEC", default_value = "reverse")]
305    pub status_style: String,
306
307    /// Style for `--prompt` output (and per-format `prompt_style`). Same
308    /// grammar as `--status-style`. Default: empty (no extra styling on top
309    /// of what the prompt template itself emits).
310    #[arg(long = "prompt-style", value_name = "SPEC", default_value = "")]
311    pub prompt_style: String,
312
313    /// Treat lines matching REGEX as record boundaries. Lines that don't
314    /// match are joined to the preceding record. Affects search, filter,
315    /// grep, and the status line — all operate on whole records when set.
316    /// Overrides the active --format's record_start if both are present.
317    /// Without --format, this is the only way to enable records mode for
318    /// plain text. Example: --record-start '^\['
319    #[arg(long = "record-start", value_name = "REGEX")]
320    pub record_start: Option<String>,
321
322    /// Synonym for `--output -`: write the batch-mode output to stdout.
323    #[arg(long = "stdout", conflicts_with = "output")]
324    pub stdout: bool,
325
326    /// Tab stop width (default 8).
327    #[arg(long = "tab-width", default_value_t = 8)]
328    pub tab_width: u8,
329
330    /// Jump to the tag NAME at startup (requires a tags file).
331    #[arg(short = 't', long = "tag", value_name = "NAME")]
332    pub tag: Option<String>,
333
334    /// Path to the tags file. Default: walk up from CWD looking for `tags`.
335    #[arg(short = 'T', long = "tag-file", value_name = "PATH")]
336    pub tag_file: Option<std::path::PathBuf>,
337
338    /// Show only the last N lines of the source. For files this skips most of
339    /// the index work — useful for huge logs. Combine with `-f` for `tail -f`.
340    /// Mutually exclusive with --head. Streaming stdin is not supported.
341    #[arg(long = "tail", value_name = "N", conflicts_with = "head")]
342    pub tail: Option<usize>,
343
344    /// Files to view (only the first is opened in MVP).
345    pub files: Vec<PathBuf>,
346}
347
348#[cfg(test)]
349mod tests {
350    use super::*;
351
352    #[test]
353    fn parses_no_flags_no_files() {
354        let a = Args::parse_from(["tess"]);
355        assert!(!a.line_numbers);
356        assert!(!a.chop);
357        assert_eq!(a.tab_width, 8);
358        assert!(a.files.is_empty());
359    }
360
361    #[test]
362    fn parses_short_flags_and_file() {
363        let a = Args::parse_from(["tess", "-N", "-S", "foo.txt"]);
364        assert!(a.line_numbers);
365        assert!(a.chop);
366        assert_eq!(a.files, vec![PathBuf::from("foo.txt")]);
367    }
368
369    #[test]
370    fn parses_tab_width() {
371        let a = Args::parse_from(["tess", "--tab-width", "4", "x"]);
372        assert_eq!(a.tab_width, 4);
373    }
374
375    #[test]
376    fn collects_multiple_files() {
377        let a = Args::parse_from(["tess", "a", "b", "c"]);
378        assert_eq!(a.files.len(), 3);
379    }
380
381    #[test]
382    fn parses_follow_short_flag() {
383        let a = Args::parse_from(["tess", "-f", "log.txt"]);
384        assert!(a.follow);
385        assert_eq!(a.files, vec![PathBuf::from("log.txt")]);
386    }
387
388    #[test]
389    fn parses_follow_long_flag() {
390        let a = Args::parse_from(["tess", "--follow"]);
391        assert!(a.follow);
392    }
393
394    #[test]
395    fn follow_defaults_off() {
396        let a = Args::parse_from(["tess", "x"]);
397        assert!(!a.follow);
398    }
399
400    #[test]
401    fn parses_head() {
402        let a = Args::parse_from(["tess", "--head", "100", "x"]);
403        assert_eq!(a.head, Some(100));
404        assert_eq!(a.tail, None);
405    }
406
407    #[test]
408    fn parses_tail() {
409        let a = Args::parse_from(["tess", "--tail", "50", "x"]);
410        assert_eq!(a.tail, Some(50));
411        assert_eq!(a.head, None);
412    }
413
414    #[test]
415    fn head_and_tail_are_mutually_exclusive() {
416        let r = Args::try_parse_from(["tess", "--head", "10", "--tail", "20", "x"]);
417        assert!(r.is_err(), "clap should reject combining --head and --tail");
418    }
419
420    #[test]
421    fn head_tail_default_to_none() {
422        let a = Args::parse_from(["tess", "x"]);
423        assert!(a.head.is_none());
424        assert!(a.tail.is_none());
425    }
426
427    #[test]
428    fn parses_grep_repeatable_and_no_format_required() {
429        let a = Args::parse_from([
430            "tess",
431            "--grep", "error",
432            "--grep", r"^\[",
433            "log",
434        ]);
435        assert_eq!(a.grep.len(), 2);
436        assert_eq!(a.grep[0], "error");
437        assert_eq!(a.grep[1], r"^\[");
438        assert_eq!(a.format, None);
439    }
440
441    #[test]
442    fn parses_format_and_filter() {
443        let a = Args::parse_from([
444            "tess", "--format", "apache-combined",
445            "--filter", "status=500",
446            "--filter", "ip~^10\\.",
447            "log",
448        ]);
449        assert_eq!(a.format.as_deref(), Some("apache-combined"));
450        assert_eq!(a.filter.len(), 2);
451        assert_eq!(a.filter[0], "status=500");
452    }
453
454    #[test]
455    fn parses_dim() {
456        let a = Args::parse_from(["tess", "--format", "x", "--filter", "y=z", "--dim", "f"]);
457        assert!(a.dim);
458    }
459
460    #[test]
461    fn parses_list_formats() {
462        let a = Args::parse_from(["tess", "--list-formats"]);
463        assert!(a.list_formats);
464    }
465
466    #[test]
467    fn parses_manual() {
468        let a = Args::parse_from(["tess", "--manual"]);
469        assert!(a.manual);
470    }
471
472    #[test]
473    fn parses_examples() {
474        let a = Args::parse_from(["tess", "--examples"]);
475        assert!(a.examples);
476    }
477
478    #[test]
479    fn parses_live() {
480        let a = Args::parse_from(["tess", "--live", "f"]);
481        assert!(a.live);
482        assert!(!a.follow);
483    }
484
485    #[test]
486    fn live_and_follow_are_mutually_exclusive() {
487        let r = Args::try_parse_from(["tess", "--live", "--follow", "f"]);
488        assert!(r.is_err(), "clap should reject combining --live and --follow");
489    }
490
491    #[test]
492    fn parses_prettify() {
493        let a = Args::parse_from(["tess", "--prettify", "f.json"]);
494        assert!(a.prettify);
495        assert_eq!(a.content_type, None);
496    }
497
498    #[test]
499    fn parses_content_type() {
500        let a = Args::parse_from(["tess", "--content-type", "json", "f"]);
501        assert_eq!(a.content_type.as_deref(), Some("json"));
502    }
503
504    #[test]
505    fn parses_output_long_and_short() {
506        let a = Args::parse_from(["tess", "-o", "/tmp/out.txt", "f"]);
507        assert_eq!(a.output.as_deref(), Some("/tmp/out.txt"));
508        let b = Args::parse_from(["tess", "--output", "/tmp/out.txt", "f"]);
509        assert_eq!(b.output.as_deref(), Some("/tmp/out.txt"));
510    }
511
512    #[test]
513    fn parses_stdout_flag() {
514        let a = Args::parse_from(["tess", "--stdout", "f"]);
515        assert!(a.stdout);
516        assert_eq!(a.output, None);
517    }
518
519    #[test]
520    fn output_and_stdout_are_mutually_exclusive() {
521        let r = Args::try_parse_from(["tess", "-o", "x", "--stdout", "f"]);
522        assert!(r.is_err(), "clap should reject combining --output and --stdout");
523    }
524
525    #[test]
526    fn parses_mouse_flag() {
527        let a = Args::parse_from(["tess", "--mouse", "f"]);
528        assert!(a.mouse);
529    }
530
531    #[test]
532    fn mouse_defaults_off() {
533        let a = Args::parse_from(["tess", "f"]);
534        assert!(!a.mouse);
535    }
536
537    #[test]
538    fn parses_no_image_flag() {
539        let a = Args::parse_from(["tess", "--no-image", "cat.png"]);
540        assert!(a.no_image);
541    }
542
543    #[test]
544    fn parses_blocks_flag() {
545        let a = Args::parse_from(["tess", "--blocks", "cat.png"]);
546        assert!(a.blocks);
547    }
548
549    #[test]
550    fn parses_image_width() {
551        let a = Args::parse_from(["tess", "--image-width", "120", "cat.png"]);
552        assert_eq!(a.image_width, Some(120));
553    }
554
555    #[test]
556    fn image_flags_default_off() {
557        let a = Args::parse_from(["tess", "f"]);
558        assert!(!a.no_image);
559        assert!(!a.blocks);
560        assert_eq!(a.image_width, None);
561    }
562
563    #[test]
564    fn help_lists_flags_in_alphabetical_order() {
565        use clap::CommandFactory;
566        let mut cmd = Args::command();
567        let help = cmd.render_help().to_string();
568
569        let expected = [
570            "--blocks",
571            "--chop-long-lines",
572            "--content-type",
573            "--dim",
574            "--display",
575            "--examples",
576            "--filter",
577            "--follow",
578            "--format",
579            "--grep",
580            "--head",
581            "--hex",
582            "--hex-group",
583            "--image-width",
584            "--LINE-NUMBERS",
585            "--list-formats",
586            "--live",
587            "--manual",
588            "--mouse",
589            "--no-color",
590            "--no-image",
591            "--no-preprocess",
592            "--output",
593            "--preprocess",
594            "--prettify",
595            "--prompt",
596            "--raw-control-chars",
597            "--record-start",
598            "--stdout",
599            "--tab-width",
600            "--tag",
601            "--tag-file",
602            "--tail",
603        ];
604        let listed: Vec<&str> = help
605            .lines()
606            .map(str::trim_start)
607            .filter(|l| l.starts_with('-'))
608            .filter_map(|l| {
609                l.split(|c: char| c.is_whitespace() || c == ',')
610                    .find(|tok| expected.contains(tok))
611            })
612            .collect();
613        assert_eq!(listed, expected, "help long-flag order should be alphabetical");
614    }
615}