accordion

Crates.ioaccordion
lib.rsaccordion
version0.1.2
created_at2025-04-16 14:57:46.24174+00
updated_at2025-05-06 09:02:01.977026+00
descriptionSimple library for Command Line Interface parsing with no magic behind the scenes
homepage
repositoryhttps://github.com/pipangry/accordion
max_upload_size
id1636555
size46,731
Pipa_ngry (pipangry)

documentation

README

Example

Creating CommandStream – assembled parser for multiple commands

use accordion::cli::command::{Arg, Command, Value};
use accordion::cli::{CommandStream, DefaultPrettifier};
use accordion::cli::consumer::GenericConsumer;

const CARGO: Command<Vec<Value>> = Command::new_from(
        "cargo",
        "Example description",
        &[
           Arg::default("subcommand"),
           Arg::flag("version", Some("v"), GenericConsumer(&[]))
        ],
        cargo
    );

let command_stream = CommandStream::new(vec![
    CARGO
    // Add more as needed
]);

// Parsing input from user
match command_stream.parse("cargo -v") {
    Ok(_) => {},
    // For potential errors we use prettifier
    Err(e) => println!("{}", command_stream.prettify(e))
}

fn cargo(_: Vec<Value>) {}

Features

  • Colors customization support out of the box
  • Automatic help command
  • Easy parsing for one or multiple commands
  • Error prettifying

Example of prettified error message

error[cargo]: 'Missing arguments: ["type", "args"]' – returned by command 'cargo'
  --> source: cargo
    | cargo ... <type> <args>
    |           ^^^^^^^^^^^^^
  help: Consider adding these arguments.
Commit count: 7

cargo fmt