Added command line parser

This commit is contained in:
Fabian Freyer
2019-07-02 04:33:49 +02:00
parent 2609425f68
commit 327cd488bb
3 changed files with 119 additions and 2 deletions
+27 -2
View File
@@ -1,12 +1,37 @@
extern crate actix;
extern crate actix_web;
extern crate webterm;
extern crate structopt;
#[macro_use]
extern crate lazy_static;
use actix_web::{fs::StaticFiles, server, App};
use structopt::StructOpt;
use webterm::WebTermExt;
use std::process::Command;
#[derive(StructOpt, Debug)]
#[structopt(name = "webterm-server")]
struct Opt {
/// The port to listen on
#[structopt(short, long, default_value = "8080")]
port: u16,
/// The host or IP to listen on
#[structopt(short, long, default_value = "localhost")]
host: String,
/// The command to execute
#[structopt(short, long, default_value = "/bin/sh")]
command: String,
}
lazy_static! {
static ref OPT: Opt = Opt::from_args();
}
fn main() {
pretty_env_logger::init();
@@ -19,13 +44,13 @@ fn main() {
.show_files_listing(),
)
.webterm_socket("/websocket", |_req| {
let mut cmd = Command::new("/bin/sh");
let mut cmd = Command::new(OPT.command.clone());
cmd.env("TERM", "xterm");
cmd
})
.webterm_ui("/", "/websocket", "/static")
})
.bind("127.0.0.1:8080")
.bind(format!("{}:{}", OPT.host, OPT.port))
.unwrap()
.run();
}