Moved parameter reader into own file

This commit is contained in:
2019-06-09 00:10:33 +02:00
parent 126d0da7c7
commit e5dc929135
3 changed files with 80 additions and 67 deletions

View File

@@ -1,57 +1,20 @@
#[macro_use]
extern crate clap;
mod configuration;
use clap::{App, Arg, ArgMatches};
use crate::configuration::Settings;
/**
* Initiates an instance of the gopherbridge server and
* starts listening for connections on the given port.
*/
fn main() {
let matches = parse_command_line();
let pluginlist = matches.value_of("PLUGIN");
let port = matches.value_of("PORT");
let settings = Settings::create();
match port {
None => println!("Default port 70 used"),
Some(p) => println!("Using port {}", p),
}
match pluginlist {
None => println!("No plugins given"),
Some(p) => println!("Loading the following plugins: {}", p),
println!("Program listens on {}", settings.listen);
println!("Loading plugins {:?}", settings.plugins);
println!("Listening on port {}", settings.port);
if settings.foreground {
println!("Server runs in the foreground");
}
}
/**
* Defines the command line parameters passed to the server and creates the
* server lines
*/
fn parse_command_line<'a>() -> ArgMatches<'a> {
return App::new("gopherbridge")
.version("0.1")
.author("jali@orca-central.de")
.about("a simple modular gopher server, that pushes converted web-content to a client")
.arg(
Arg::with_name("FORGROUND")
.short("f")
.long("foreground")
.help("Keeps the service in the foreground")
.takes_value(false),
)
.arg(
Arg::with_name("PLUGIN")
.short("l")
.long("plugins")
.value_name("PLUGINLIST")
.takes_value(true)
.index(1),
)
.arg(
Arg::with_name("PORT")
.short("p")
.long("port")
.help("Specifies the port the server listens on. Default is 70")
.takes_value(true),
)
.get_matches();
}