Add CLI parsing using clap
Diff
Cargo.lock | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
Cargo.toml | 2 +-
src/client.rs | 2 +-
src/config.rs | 9 +++++++++
src/main.rs | 18 ++++++++++++++++++
5 files changed, 78 insertions(+), 3 deletions(-)
@@ -131,6 +131,7 @@
checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39"
dependencies = [
"bitflags",
"clap_derive",
"clap_lex",
"is-terminal",
"once_cell",
@@ -139,6 +140,19 @@
]
[[package]]
name = "clap_derive"
version = "4.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -405,6 +419,12 @@
"pin-utils",
"slab",
]
[[package]]
name = "heck"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9"
[[package]]
name = "hermit-abi"
@@ -661,6 +681,30 @@
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
@@ -1038,6 +1082,12 @@
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "version_check"
version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "wasi"
@@ -10,7 +10,7 @@
actix-rt = "2.7"
anyhow = "1.0"
chrono = "0.4"
clap = { version = "4.0", features = ["cargo"] }
clap = { version = "4.0", features = ["cargo", "derive", "std", "suggestions", "color"] }
futures = "0.3"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
@@ -6,7 +6,7 @@
};
use clap::{crate_name, crate_version};
use futures::FutureExt;
use irc_proto::{error::ProtocolError, ChannelExt, Command, Message, Response, Prefix};
use irc_proto::{error::ProtocolError, ChannelExt, Command, Message, Prefix, Response};
use tokio::time::Instant;
use tracing::{debug, error, info_span, instrument, warn, Instrument, Span};
@@ -1,0 +1,9 @@
use clap::Parser;
#[derive(Parser)]
#[clap(version = clap::crate_version!(), author = clap::crate_authors!())]
pub struct Args {
#[clap(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
}
@@ -5,16 +5,18 @@
use actix::{io::FramedWrite, Actor, Addr, AsyncContext};
use actix_rt::System;
use clap::Parser;
use irc_proto::IrcCodec;
use tokio::{net::TcpListener, time::Instant};
use tokio_util::codec::FramedRead;
use tracing::{error, info, info_span, Instrument};
use tracing_subscriber::EnvFilter;
use crate::{client::Client, messages::UserConnected, server::Server};
use crate::{client::Client, config::Args, messages::UserConnected, server::Server};
pub mod channel;
pub mod client;
pub mod config;
pub mod connection;
pub mod messages;
pub mod server;
@@ -23,6 +25,20 @@
#[actix_rt::main]
async fn main() -> anyhow::Result<()> {
let opts: Args = Args::parse();
std::env::set_var(
"RUST_LOG",
match opts.verbose {
1 => "debug",
2 => "trace",
_ => "info",
},
);
let subscriber = tracing_subscriber::fmt()
.with_env_filter(EnvFilter::from_default_env())
.pretty();