generated from PlexSheep/rs-base
Compare commits
No commits in common. "69615cf4d57190708f0f5318ae72f47acf9f1c32" and "716c02da5d50ca46ac70117d38794b49d699b13f" have entirely different histories.
69615cf4d5
...
716c02da5d
4 changed files with 12 additions and 62 deletions
|
@ -1,38 +0,0 @@
|
||||||
use std::fmt::Display;
|
|
||||||
|
|
||||||
use clap::ValueEnum;
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub(crate) enum Mode {
|
|
||||||
Tcp,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ValueEnum for Mode {
|
|
||||||
fn to_possible_value(&self) -> Option<clap::builder::PossibleValue> {
|
|
||||||
Some(match self {
|
|
||||||
Self::Tcp => clap::builder::PossibleValue::new("tcp"),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
fn value_variants<'a>() -> &'a [Self] {
|
|
||||||
&[Self::Tcp]
|
|
||||||
}
|
|
||||||
fn from_str(input: &str, ignore_case: bool) -> Result<Self, String> {
|
|
||||||
let comp: String = if ignore_case {
|
|
||||||
input.to_lowercase()
|
|
||||||
} else {
|
|
||||||
input.to_string()
|
|
||||||
};
|
|
||||||
match comp.as_str() {
|
|
||||||
"tcp" => return Ok(Self::Tcp),
|
|
||||||
_ => return Err(format!("\"{input}\" is not a valid mode")),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Display for Mode {
|
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let repr: String = match self{
|
|
||||||
Self::Tcp => format!("tcp")
|
|
||||||
};
|
|
||||||
write!(f, "{}", repr)
|
|
||||||
}
|
|
||||||
}
|
|
36
src/main.rs
36
src/main.rs
|
@ -8,11 +8,13 @@ use libpt::log::*;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
use clap_verbosity_flag::{InfoLevel, Verbosity};
|
||||||
|
|
||||||
mod client;
|
/// Chose a mode for the application to run in, server needs more than client.
|
||||||
mod common;
|
enum Mode {
|
||||||
mod server;
|
#[cfg(feature = "server")]
|
||||||
|
Server,
|
||||||
use common::Mode;
|
#[cfg(feature = "client")]
|
||||||
|
Client,
|
||||||
|
}
|
||||||
|
|
||||||
/// short about section displayed in help
|
/// short about section displayed in help
|
||||||
const ABOUT_ROOT: &'static str = r##"
|
const ABOUT_ROOT: &'static str = r##"
|
||||||
|
@ -40,25 +42,18 @@ libpt: {version}
|
||||||
Author: {author-with-newline}
|
Author: {author-with-newline}
|
||||||
"#
|
"#
|
||||||
)]
|
)]
|
||||||
pub(crate) struct Cli {
|
pub struct Cli {
|
||||||
// clap_verbosity_flag seems to make this a global option implicitly
|
// clap_verbosity_flag seems to make this a global option implicitly
|
||||||
/// set a verbosity, multiple allowed (f.e. -vvv)
|
/// set a verbosity, multiple allowed (f.e. -vvv)
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
pub(crate) verbose: Verbosity<InfoLevel>,
|
pub verbose: Verbosity<InfoLevel>,
|
||||||
|
|
||||||
/// show additional logging meta data
|
/// show additional logging meta data
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub(crate) meta: bool,
|
pub meta: bool,
|
||||||
|
|
||||||
#[cfg(feature = "server")]
|
|
||||||
#[arg(short, long, default_value_t = false)]
|
|
||||||
pub(crate) server: bool,
|
|
||||||
|
|
||||||
#[arg(short, long, default_value_t = Mode::Tcp, ignore_case = true)]
|
|
||||||
pub(crate) mode: Mode,
|
|
||||||
|
|
||||||
/// Address of the server
|
/// Address of the server
|
||||||
pub(crate) addr: std::net::SocketAddr,
|
pub addr: std::net::SocketAddr,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cli_parse() -> Cli {
|
fn cli_parse() -> Cli {
|
||||||
|
@ -85,12 +80,5 @@ fn cli_parse() -> Cli {
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = cli_parse();
|
let cli = cli_parse();
|
||||||
debug!("dumping cli args:\n{:#?}", cli);
|
debug!("dumping cli args:\n{:#?}", cli);
|
||||||
#[cfg(feature = "server")]
|
println!("Hello, world!");
|
||||||
if cli.server {
|
|
||||||
info!("starting server");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// implicit else, so we can work without the server feature
|
|
||||||
info!("starting client");
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue