args-extractor 0.1.0

Args command line extractor library for Rust applications
Documentation
  • Coverage
  • 12.5%
    1 out of 8 items documented1 out of 1 items with examples
  • Size
  • Source code size: 49.97 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 498.44 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Skewnart/args-extractor
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Skewnart

Args Extractor

Extracting arguments from a command line (prompt) is much easier than ever !

Classic usage

For this prompt : echo "hello world" | ./your_program arg1 arg2 -i -f file.txt

PromptExtractor will extract :

  • program_name : "./your_program"
  • content_piped : Some("hello world\n")
  • arguments : Some(["arg1", "arg2"])
  • parameters: Some({"-i": [], "-f": ["file.txt"]})
use args_extractor::{Prompt, PromptExtractor};

fn main() -> Result<(), String> {
    let prompt = PromptExtractor::extract()?;
    println!("{:?}", prompt);

    // # For your own Configuration building process
    // let config = Config::build(prompt)?;

    Ok(())
}

Mock usage

use args_extractor::{Prompt, PromptExtractor};
use std::vec::IntoIter;

fn string_into_iter(input: &str) -> IntoIter<String> {
    input.split_whitespace().map(String::from).collect::<Vec<String>>().into_iter()
}

fn main() -> Result<(), String> {
    let args = string_into_iter("program.exe arg1 arg2 -i -f file.txt");
    let prompt = PromptExtractor::extract_from(args)?;
    println!("{:?}", prompt);

    // # For your own Configuration building process
    // let config = Config::build(prompt)?;

    Ok(())
}