assert_sorted

Function assert_sorted 

Source
pub fn assert_sorted(cmd: &Command)
Expand description

Validates that subcommands and arguments are sorted correctly.

This checks:

  • Subcommands are sorted alphabetically
  • Arguments are grouped and sorted by type:
    1. Positional arguments (order not enforced)
    2. Flags with short options (alphabetically by short option)
    3. Long-only flags (alphabetically)

Recursively validates all subcommands.

§Panics

Panics if subcommands or arguments are not properly sorted.

§Example

use clap::{Command, Arg};

let cmd = Command::new("mycli")
    .arg(Arg::new("file"))  // Positional
    .arg(Arg::new("output").short('o').long("output"))  // Short flag
    .arg(Arg::new("config").long("config"));  // Long-only flag

clap_sort::assert_sorted(&cmd);