You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
phd/src/main.rs

63 lines
1.5 KiB
Rust

4 years ago
use phd;
4 years ago
use std::process;
5 years ago
fn main() {
4 years ago
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
print_help();
4 years ago
return;
}
let mut root = ".";
let mut iter = args.iter();
let mut host = "localhost";
let mut port = "70";
while let Some(arg) = iter.next() {
match arg.as_ref() {
"--version" | "-v" | "-version" => return print_version(),
"--help" | "-h" | "-help" => return print_help(),
"--port" | "-p" | "-port" => {
if let Some(p) = iter.next() {
port = p;
}
}
"--host" | "-H" | "-host" => {
if let Some(h) = iter.next() {
host = h;
}
}
_ => {
if let Some('-') = arg.chars().nth(0) {
eprintln!("unknown flag: {}", arg);
process::exit(1);
} else {
root = arg;
}
}
}
4 years ago
}
if let Err(e) = phd::server::start(host, port, root) {
5 years ago
eprintln!("{}", e);
}
}
4 years ago
fn print_help() {
4 years ago
println!(
"Usage:
phd [options] <root>
Options:
-p, --port Port to bind to.
-H, --host Hostname to use when generating links.
-h, --help Print this screen.
-v, --version Print phd version."
);
}
fn print_version() {
println!("phd v{}", env!("CARGO_PKG_VERSION"));
}