aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2019-05-09 22:12:18 +0200
committerHarald Eilertsen <haraldei@anduin.net>2019-05-09 22:12:18 +0200
commit8632549a8e14938db686396a12876de57da7d4d0 (patch)
tree8c11367e3e267ab64a6c594c79367fb85822abe3
parent4c489c4dd4ffaf74d718035f73fa3c0f762d1187 (diff)
downloadphisher-master.tar.gz
phisher-master.tar.bz2
phisher-master.zip
Refactoring, move arg parsing and sig handler out of main.HEADmaster
-rw-r--r--src/main.rs39
1 files changed, 24 insertions, 15 deletions
diff --git a/src/main.rs b/src/main.rs
index 36c5cf9..bee16bb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
use phisher;
-use clap::{clap_app, crate_name, crate_authors, crate_version, crate_description};
+use clap::{ArgMatches, clap_app, crate_name, crate_authors, crate_version, crate_description};
use std::boxed::Box;
use std::error::Error;
use std::fs::{ File, remove_file };
@@ -29,20 +29,8 @@ use std::thread;
use std::time::SystemTime;
fn main() {
- // Set signal handler to clean up on termination.
- ctrlc::set_handler(move || {
- // We don't care about errors in remove_file.
- remove_file("/tmp/phisher").unwrap_or(());
- exit(0);
- }).expect("Couldn't set signal handler!");
-
- let args = clap_app!(app =>
- (name: crate_name!())
- (version: crate_version!())
- (author: crate_authors!())
- (about: crate_description!())
- (@arg PHISHTANK: --phishtank +required +takes_value "The phishtank json data file to use.")
- ).get_matches();
+ let args = get_args();
+ set_sig_handler();
let start_time = SystemTime::now();
let filename = args.value_of("PHISHTANK").unwrap();
@@ -63,6 +51,27 @@ fn main() {
}
}
+fn get_args() -> ArgMatches<'static> {
+ clap_app!(app =>
+ (name: crate_name!())
+ (version: crate_version!())
+ (author: crate_authors!())
+ (about: crate_description!())
+ (@arg PHISHTANK: --phishtank +required +takes_value
+ "The phishtank json data file to use.")
+ ).get_matches()
+}
+
+// Set signal handler to clean up on termination.
+//
+fn set_sig_handler() {
+ ctrlc::set_handler(move || {
+ // We don't care about errors in remove_file.
+ remove_file("/tmp/phisher").unwrap_or(());
+ exit(0);
+ }).expect("Couldn't set signal handler!");
+}
+
fn run_server(tank: Arc<phisher::PhishTank>) -> Result<(), Box<dyn Error>> {
let bind_address = "/tmp/phisher";
let listener = UnixListener::bind(&bind_address)?;