Skip to content

Commit

Permalink
Performed Code Reuse/Reduction for Single and Multiple Hostnames argu…
Browse files Browse the repository at this point in the history
…ments to use in the major workflow!
  • Loading branch information
TheBinitGhimire committed Jan 21, 2022
1 parent 6890192 commit 090b4af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
6 changes: 2 additions & 4 deletions src/io.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
use super::takeover::_takeover;

use std::fs::{File, OpenOptions};
use std::io::prelude::*;
use std::io::{BufRead, BufReader, BufWriter};

pub fn _fileRead(filepath: String, threads: usize) {
pub fn _fileRead(filepath: String) -> Vec<String> {
let file = File::open(filepath).expect("Unable to open file!");
let reader = BufReader::new(file);
let mut hosts = Vec::<String>::new();
for line in reader.lines() {
hosts.push(line.unwrap());
}
_takeover(hosts, threads);
return hosts;
}

pub fn _writeOutput(fileName: String, outputData: String) {
Expand Down
18 changes: 10 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,17 @@ fn main() -> std::io::Result<()> {
if args.is_present("file") && args.is_present("target") {
println!("Please provide either a single hostname or a file containing list of hostnames rather than both!");
exit(1);
} else if args.is_present("file") {
let hostnames = args.value_of("file").unwrap_or("hostnames.txt");
_fileRead(hostnames.to_string(), _threads);
} else if args.is_present("target") {
let _target = args.value_of("target").unwrap();
let mut hosts = Vec::<String>::new();
hosts.push(_target.to_string());
} else {
let mut hosts = Vec::<String>::new();
if args.is_present("file") {
let hostnames = args.value_of("file").unwrap_or("hostnames.txt");
hosts = _fileRead(hostnames.to_string());
} else if args.is_present("target") {
let _target = args.value_of("target").unwrap();
hosts.push(_target.to_string());
}
_takeover(hosts, _threads);
}

Ok(())
}

0 comments on commit 090b4af

Please sign in to comment.