Use clap for arg parsing in server, get rid of default values

This commit is contained in:
Jan Trefil 2023-04-16 12:48:31 +02:00
parent 17558d0fec
commit 437c3398f0
3 changed files with 5 additions and 13 deletions

2
Cargo.lock generated
View file

@ -829,12 +829,12 @@ name = "rkvm-server"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap 4.2.2",
"env_logger 0.8.4", "env_logger 0.8.4",
"log", "log",
"rkvm-input", "rkvm-input",
"rkvm-net", "rkvm-net",
"serde", "serde",
"structopt",
"tokio", "tokio",
"tokio-native-tls", "tokio-native-tls",
"toml", "toml",

View file

@ -13,11 +13,11 @@ rkvm-input = { path = "../rkvm-input" }
rkvm-net = { path = "../rkvm-net" } rkvm-net = { path = "../rkvm-net" }
serde = { version = "1.0.117", features = ["derive"] } serde = { version = "1.0.117", features = ["derive"] }
toml = "0.5.7" toml = "0.5.7"
structopt = "0.3.20"
log = "0.4.11" log = "0.4.11"
env_logger = "0.8.1" env_logger = "0.8.1"
tokio-native-tls = "0.3.0" tokio-native-tls = "0.3.0"
anyhow = "1.0.33" anyhow = "1.0.33"
clap = { version = "4.2.2", features = ["derive"] }
[package.metadata.rpm] [package.metadata.rpm]
package = "rkvm-server" package = "rkvm-server"

View file

@ -10,7 +10,7 @@ use std::convert::Infallible;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process; use std::process;
use structopt::StructOpt; use clap::Parser;
use tokio::fs; use tokio::fs;
use tokio::io::{AsyncRead, AsyncWrite}; use tokio::io::{AsyncRead, AsyncWrite};
use tokio::net::TcpListener; use tokio::net::TcpListener;
@ -155,18 +155,10 @@ async fn run(
} }
} }
#[derive(StructOpt)] #[derive(Parser)]
#[structopt(name = "rkvm-server", about = "The rkvm server application")] #[structopt(name = "rkvm-server", about = "The rkvm server application")]
struct Args { struct Args {
#[structopt(help = "Path to configuration file")] #[structopt(help = "Path to configuration file")]
#[cfg_attr(
target_os = "linux",
structopt(default_value = "/etc/rkvm/server.toml")
)]
#[cfg_attr(
target_os = "windows",
structopt(default_value = "C:/rkvm/server.toml")
)]
config_path: PathBuf, config_path: PathBuf,
} }
@ -177,7 +169,7 @@ async fn main() {
.filter(None, LevelFilter::Info) .filter(None, LevelFilter::Info)
.init(); .init();
let args = Args::from_args(); let args = Args::parse();
let config = match fs::read_to_string(&args.config_path).await { let config = match fs::read_to_string(&args.config_path).await {
Ok(config) => config, Ok(config) => config,
Err(err) => { Err(err) => {