# Yaccas [![Build Status](https://travis-ci.org/Christopher22/yaccas.svg?branch=master)](https://travis-ci.org/Christopher22/yaccas) **Y**et **A**nother **C**allback-orientated **C**ommand line p**A**r**S**er is ... well, yet another command line parser. ## Features or "Yet another?! You are not that creative, are you?!" Indeed, there are so many command line parser written in Rust out there... But would I have written this one if it is like all the other? Let me convince you: Why should you choose this one? - Smoothly to integrate into existing projects - Extreme lightweight, easy & fast - Zero dependencies: Only pure Rust! - No handler, references or other bullshit: Just modern callbacks! - Ready for every system: Accept the syntax of UNIX exactly like that one of WINDOWS. - Completely documented, many (doc-)tests to check correctness ## Documentation [Documentation on GitHub](https://christopher22.github.io/yaccas/yaccas/) ## Example There are two ways to use Yaccas: The preferred callback-oriented method or a argument-oriented one. ```Rust #[macro_use] extern crate yaccas; use yaccas::arguments::{Argument, Command, Flag, Value}; use yaccas::parser::{Parser, FreeArgumentSupport, Result}; fn method_with_callback() { let mut will_be_true_if_flag_is_set = false; let mut will_be_42_as_everytime = 0u32; { // It's time for some magic ... // There a three types of arguments let flag = Flag::default(); let value = Value::new::(); let command = Command::new(|| Some("A fancy name for abort")); // Registers the arguments to a parser. // All callbacks will only be executed if parsing was successful! let mut parser = Parser::default(); parser.register(&["option", "o1", "o2"], Argument::with_callback(flag, | flag | { // Flags are options which may occur 0 - x times. will_be_true_if_flag_is_set = flag.is_activated(); })); parser.register(&["value", "v"], Argument::with_callback(value, | value | { // Values are command line argument-value pairs of a specific type. will_be_42_as_everytime = value.get_value::().expect("The answer for everything is 42!"); })); parser.register(&["abort"], Argument::with_callback(command, | _command | { // Commands may or may not abort the execution of parsing, i.e. for "help". // This callback is a fallback: It is only called if the process was not aborted! })); match parser.parse(default_scanner!()) { Result::Success(free_arguments) => { /* ... */ }, Result::Aborted("A fancy name for abort") => { /* ... */ }, _ => { /* ... */ } } } // Do something with "will_be_true_if_flag_is_set" or "will_be_42_as_everytime" here ... } fn method_without_callback() { let mut flag = Flag::default(); let mut value = Value::new::(); let mut command = Command::new(|| Some("A fancy name for abort")); { // It's time for some magic ... // Registers the arguments to a parser. let mut parser = Parser::default(); parser.register(&["option", "o1", "o2"], flag); parser.register(&["value", "v"], value); parser.register(&["abort"], command); match parser.parse(default_scanner!()) { Result::Success(free_arguments) => { /* ... */ }, Result::Aborted("A fancy name for abort") => { /* Abort execution */ }, _ => { /* Abort execution */ } } } // Access arguments directly here to access i.e. their values. } ``` ##Author Christopher Gundler () ##License Licensed under either of * Apache License, Version 2.0, (http://www.apache.org/licenses/LICENSE-2.0) * MIT license (http://opensource.org/licenses/MIT) at your option. ##Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.