shift

Crates.ioshift
lib.rsshift
version0.2.0
created_at2025-07-08 01:42:18.000994+00
updated_at2025-07-08 03:39:18.847046+00
descriptionA command-line argument parser
homepage
repositoryhttps://codeberg.org/eze-works/argsplz
max_upload_size
id1741954
size16,371
(eze-works)

documentation

README

shift

Unobtrusive library for processing command line arguments.

pub fn main() {
    // Assume this is the result of std::env::args()
    let cmdline = ["git", "--help", "commit", "--message", "hello"];
    let mut args = shift::parse(
        cmdline.into_iter().map(|s| s.to_string()).collect()
    ).unwrap();

    // Detect help flags
    if args.shift_flag("help") || args.shift_flag("h") {
        // Show help
    }

    // Detect positional arguments with known values (aka "commands")
    if args.shift_operand_with_value("commit") {
        // Do the commit
    }

    // Get the value of an option
    let Some(value) = args.shift_option("m").or_else(|| args.shift_option("message")) else {
        panic!();
    };
    assert_eq!(value, "hello");
}
Commit count: 0

cargo fmt