diff --git a/mega/src/cli.rs b/mega/src/cli.rs index 73e4d335e..fd496a4fe 100644 --- a/mega/src/cli.rs +++ b/mega/src/cli.rs @@ -20,8 +20,11 @@ use crate::commands::{builtin, builtin_exec}; /// /// This function returns a `MegaResult`. If the parsing is successful, it will return the result. /// If there is an error during the parsing, it will return an error. -pub fn parse() -> MegaResult { - let matches = cli().try_get_matches().unwrap_or_else(|e| e.exit()); +pub fn parse(args: Option>) -> MegaResult { + let matches = match args { + Some(args) => cli().no_binary_name(true).try_get_matches_from(args).unwrap_or_else(|e| e.exit()), + None => cli().try_get_matches().unwrap_or_else(|e| e.exit()) + }; // Get the current directory let current_dir = env::current_dir()?; diff --git a/mega/src/lib.rs b/mega/src/lib.rs new file mode 100644 index 000000000..3ae7f75a0 --- /dev/null +++ b/mega/src/lib.rs @@ -0,0 +1,13 @@ +pub mod cli; +mod commands; + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_cli() { + let args = "service http".split(' ').collect(); + cli::parse(Some(args)).expect("Failed to start http service"); + } +} \ No newline at end of file diff --git a/mega/src/main.rs b/mega/src/main.rs index dd9029ffe..da8da7a56 100644 --- a/mega/src/main.rs +++ b/mega/src/main.rs @@ -9,7 +9,7 @@ mod commands; fn main() { // Parse the command line arguments - let result = cli::parse(); + let result = cli::parse(None); // If there was an error, print it if let Err(e) = result {