1 unstable release

0.1.0 Apr 25, 2025

#661 in Build Utils

Download history 108/week @ 2025-04-22 24/week @ 2025-04-29 10/week @ 2025-05-06

142 downloads per month
Used in xtask-cmdwrap

MIT license

9KB
144 lines

Command wrappers for cargo xtask pattern

[!IMPORTANT] This is a work in progress, nothing is guaranteed (yet)

Usage

The main idea is to define commands one of the following ways:

  • Single/double dash specifier on arguments
      use std::ffi::OsStr;
    
      #[command]
      struct Echo {
          /// Do not output the trailing newline
          #[arg(single)]
          n: bool,
          /// Enable interpretation fo backslash escapes
          #[arg(single)]
          e: bool,
          /// Display help and exit
          #[arg(double)]
          help: bool,
          /// Display version info and exit
          #[arg(double)]
          version:bool,
          /// The string to echo
          string: OsStr,
      }
    
  • Specifier for everything, sensible defaults
    • Defaults:
      • prefix="--"
      • postfix=" "
      • name=IDENT
      • flag is absent
    • Example:
      use std::ffi::OsStr;
      
      #[cmd(name="/bin/echo")]
      struct Echo {
          /// Do not output the trailing newline
          #[cmd::opt(flag, prefix="-", name="n")]
          no_newline: bool,
          /// Enable interpretation fo backslash escapes
          #[cmd::opt(flag, prefix="-", name="e")]
          escape: bool,
          /// Display help and exit
          #[cmd::opt(flag, prefix="--")]
          help: bool,
          /// Display version info and exit
          #[cmd::opt(flag, prefix="--")]
          version: bool,
          /// The string to echo
          string: OsStr,
      }
      
    • Result:
      /bin/echo [-n] [-e] [--help] [--version] STRING
      

Dependencies

~1–1.4MB
~30K SLoC