command_parser/lib.rs
1//! # Command Syntax
2//!
3//! In any examples in this documentation `!` will be used as a prefix and `-` will be used as a option prefix.
4//!
5//! A command that this can parse could look like this:
6//!
7//! `!foo arg1 "long arg 2" -opt -opt -key1:val1 -key2:"long val2"`
8//!
9//! A command consists of 4 different parts:
10//! - _name_: The name of the command is the first word after the prefix.
11//! In the example above that's `foo`.
12//! - _arguments_: Arguments are simple strings passed to the command.
13//! They are either single words or strings with spaces enclosed by `"`.
14//! In the example the two arguments are `arg1` and `long arg 2`.
15//! - _options_: Options are a set of words.
16//! They are prefixed with the `option_prefix`.
17//! The only option in the example is `opt`.
18//! - _parameters_: Parameters are key-value pairs.
19//! They are prefixed with the `option_prefix` and seperated by `:`.
20//! The value part of the pair can be a word or a string enclosed by `"`.
21//! In the example above `key1`s value is `val1` and `key2`s value is `long val2`.
22//!
23//! # Escaping
24//!
25//! Since `"` is used to mark the borders of long arguments and values, it's not normally possible
26//! to include them in the string of the argument.
27//!
28//! You can escape a long argument or value using \\:
29//! - `\"`: produces `"`
30//! - `\\`: produces `\`
31//!
32//! # Example
33//!
34//! ```
35//! use std::collections::{HashMap, HashSet};
36//! use command_parser::{Parser, Command};
37//!
38//! let p = Parser::new('!', '-');
39//! let command_string = r##"!foo arg1 "long arg 2" -opt -opt -key1:val1 -key2:"long val2""##;
40//! let command = p.parse(command_string).unwrap();
41//!
42//! assert_eq!(command.name, "foo");
43//! assert_eq!(command.arguments[1], "long arg 2");
44//! assert!(command.options.contains("opt"));
45//! assert_eq!(command.parameters.get("key2"), Some(&"long val2".to_string()));
46//! ```
47
48mod command;
49mod error;
50mod parser;
51
52pub use parser::*;
53pub use command::*;
54pub use error::*;