Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mega/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<&str>>) -> 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()?;
Expand Down
13 changes: 13 additions & 0 deletions mega/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
2 changes: 1 addition & 1 deletion mega/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down