1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
//! Utilities for parsing command line arguments //! //! `entrance` provides type assisted tools for parsing command line argumuments. //! //! # Usage //! //! ``` //! use entrance::*; //! use std::path::PathBuf; //! //! #[derive(Options)] //! struct Opts { //! #[description = "Print help message"] //! #[short = 'h'] //! help: bool, //! //! #[description = "Use verbose output"] //! #[short = 'v'] //! verbose: bool, //! //! #[description = "Print version information"] //! version: bool, //! } //! //! #[derive(Arguments)] //! struct Args { //! #[description = "Path to a file"] //! path: PathBuf, //! } //! //! let args = ["program", "-v", "path/to/file"].iter().map(|s| s.to_string()); //! //! // Parse only options to exit immediately with "--version" or "--help". //! let command = Command::<Opts, Args>::new("program").parse_options(args).unwrap(); //! //! if command.options().version { //! // Print version information and exit. //! } //! //! if command.options().help { //! println!("{}", command.help()); //! // Exit //! } //! //! // Parse the other arguments //! let command = command.parse_arguments().unwrap(); //! //! assert!(!command.options().help); //! assert!(!command.options().version); //! assert!(command.options().verbose); //! //! assert_eq!(command.arguments().path, PathBuf::from("path/to/file")); //! ``` mod arguments; mod command; mod options; pub use crate::arguments::*; pub use crate::command::*; pub use crate::options::*; pub use entrance_derive::*; use std::error; pub type Result<T> = std::result::Result<T, Box<dyn error::Error>>;