git_eq/
config.rs

1use std::env;
2
3const DEFAULT_MESSAGE: &str = "Earthquake!!! This is an emergency commit";
4
5/// Structure holding the configuration
6pub struct Config {
7    /// The message used for the commit
8    pub commit_message: String,
9}
10
11impl Config {
12    /// Creates a new Config using the arguments
13    pub fn new(mut args: env::Args) -> (Self, Option<&'static str>) {
14        // ignoring the first parameter (always the program's full path)
15        args.next();
16
17        let commit_message = match args.next() {
18            Some(s) => s,
19            None => DEFAULT_MESSAGE.to_owned(),
20        };
21
22        let mut warning = Option::None;
23        if args.len() > 0 {
24            warning = Option::Some("Warning: Too many arguments passed. Arguments after commit message are being ignored");
25        }
26
27        (Self { commit_message }, warning)
28    }
29}