Skip to content

Commit

Permalink
Add option to exclude object exportation
Browse files Browse the repository at this point in the history
  • Loading branch information
ruieduardolopes committed Oct 21, 2019
1 parent 1bdd042 commit 109e34d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ fn main() {
Some(filter_string) => filter = Regex::new(filter_string).unwrap(),
None => filter = Regex::new(".*").unwrap(),
}
match subcommands::run::init(ingress, egress, filter) {
let export = cliopts.subcommand_matches(subcommand_string).unwrap().is_present("export-objects");
match subcommands::run::init(ingress, egress, filter, export) {
Ok(_) => {}
Err(_) => {}
}
Expand Down
10 changes: 9 additions & 1 deletion src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use clap::{App, Arg, ArgMatches, SubCommand};

pub fn get_options_from_cli() -> ArgMatches<'static> {
App::new("Monet: Monitor a Network")
.version("0.1.5-rc8")
.version("0.1.5-rc9")
.author("André Nascimento and Rui Lopes")
.about("Tool to get some insights on a network or interfaces")
.subcommand(
Expand All @@ -25,6 +25,14 @@ pub fn get_options_from_cli() -> ArgMatches<'static> {
.default_value("")
.help("Set of egress interfaces, between quotes: i.e. \"enp0s1,wlan0\"")
)
.arg(
Arg::with_name("export-objects")
.takes_value(false)
.long("export")
.short("O")
.required(false)
.help("Flag if you want to export captures as monet's files.")
)
.arg(
Arg::with_name("filter")
.takes_value(true)
Expand Down
37 changes: 19 additions & 18 deletions src/subcommands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::capture::results::CaptureResult;
use crate::structs::node::status::NodeStatus;
use crate::structs::node::Node;

pub fn init(ingress: String, egress: String, filter: Regex) -> Result<(), Error> {
pub fn init(ingress: String, egress: String, filter: Regex, export: bool) -> Result<(), Error> {
// Start both ingress and egress captures.
thread::scope(|scope| {
let home = match env::var_os("HOME") {
Expand Down Expand Up @@ -85,25 +85,26 @@ pub fn init(ingress: String, egress: String, filter: Regex) -> Result<(), Error>
}
}
}

let mut file = OpenOptions::new()
.create_new(true)
.write(true)
.open(if *is_ingress {
println!(
"\nTrying to create {}",
if export {
let mut file = OpenOptions::new()
.create_new(true)
.write(true)
.open(if *is_ingress {
println!(
"\nTrying to create {}",
format!("{}/.monet/ingress-{}.monet", home.display(), interface)
);
format!("{}/.monet/ingress-{}.monet", home.display(), interface)
);
format!("{}/.monet/ingress-{}.monet", home.display(), interface)
} else {
println!(
"\nTrying to create {}",
} else {
println!(
"\nTrying to create {}",
format!("{}/.monet/egress-{}.monet", home.display(), interface)
);
format!("{}/.monet/egress-{}.monet", home.display(), interface)
);
format!("{}/.monet/egress-{}.monet", home.display(), interface)
})
.unwrap();
bincode::serialize_into(&mut file, &capture).unwrap();
})
.unwrap();
bincode::serialize_into(&mut file, &capture).unwrap();
}
});
std::process::exit(0);
});
Expand Down

0 comments on commit 109e34d

Please sign in to comment.