Skip to content

Commit

Permalink
Using clap to handle options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Tricaud committed Dec 22, 2019
1 parent 7efb953 commit 7f87007
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ rust-ini = "0.13.0"
openssl = "0.10.23"
base64 = "0.10.1"
#memory-balloon = "0.1.0"
clap = "2.33.0"

[dependencies.chrono]
version = "0.4.7"
Expand Down
38 changes: 35 additions & 3 deletions src/daemon/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
extern crate daemonize;
extern crate ansi_term;

extern crate clap;

mod sighting_writer;
mod sighting_reader;
mod sighting_configure;
mod attribute;
mod db;

use clap::Arg;
use std::sync::Arc;
use std::sync::Mutex;

Expand Down Expand Up @@ -145,12 +146,43 @@ fn write_bulk(data: web::Data<Arc<Mutex<SharedState>>>, postdata: web::Json<Post
return HttpResponse::Ok().json(Message{message: String::from("Invalid base64 encoding (base64 url with non padding) value")});
}

fn main() {
fn sightingdb_get_config() -> String {
return String::from("config path");
}

fn main() {
let mut sharedstate = Arc::new(Mutex::new(SharedState::new()));

let matches = clap::App::new("SightingDB")
.version("0.0.1")
.author("Sebastien Tricaud <[email protected]>")
.about("Counting Database")
.arg(Arg::with_name("config")
.short("c")
.long("config")
.value_name("FILE")
.help("Sets a custom config file")
.takes_value(true))
.arg(Arg::with_name("v")
.short("v")
.multiple(true)
.help("Sets the level of verbosity"))
.get_matches();

let config = matches.value_of("config").unwrap_or("sighting-daemon.ini");
println!("Value for config: {}", config);

match matches.occurrences_of("v") {
0 => println!("No verbose info"),
1 => println!("Some verbose info"),
2 => println!("Tons of verbose info"),
3 | _ => println!("Don't be crazy"),
}

let config = Ini::load_from_file("sighting-daemon.ini").unwrap();

let sightingdb_ini_file = sightingdb_get_config();
println!("SightingDB INI file: {}", sightingdb_ini_file);

let daemon_config = config.section(Some("daemon")).unwrap();

let listen_ip = daemon_config.get("listen_ip").unwrap();
Expand Down

0 comments on commit 7f87007

Please sign in to comment.