mirror of
https://github.com/chirpstack/chirpstack.git
synced 2025-02-20 17:12:48 +00:00
Update clap to v4.
This commit is contained in:
parent
a91fb1f73e
commit
4282d3aedc
43
Cargo.lock
generated
43
Cargo.lock
generated
@ -731,7 +731,7 @@ dependencies = [
|
||||
"bitflags",
|
||||
"cexpr",
|
||||
"clang-sys",
|
||||
"clap",
|
||||
"clap 3.2.22",
|
||||
"env_logger",
|
||||
"lazy_static",
|
||||
"lazycell",
|
||||
@ -904,7 +904,7 @@ dependencies = [
|
||||
"bytes",
|
||||
"chirpstack_api",
|
||||
"chrono",
|
||||
"clap",
|
||||
"clap 4.0.8",
|
||||
"diesel",
|
||||
"diesel_migrations",
|
||||
"futures",
|
||||
@ -1028,13 +1028,41 @@ checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_lex",
|
||||
"clap_lex 0.2.4",
|
||||
"indexmap",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
"textwrap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5840cd9093aabeabf7fd932754c435b7674520fc3ddc935c397837050f0f1e4b"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
"clap_derive",
|
||||
"clap_lex 0.3.0",
|
||||
"once_cell",
|
||||
"strsim",
|
||||
"termcolor",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92289ffc6fb4a85d85c246ddb874c05a87a2e540fb6ad52f7ca07c8c1e1840b1"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-error",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.2.4"
|
||||
@ -1044,6 +1072,15 @@ dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
|
||||
dependencies = [
|
||||
"os_str_bytes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cmac"
|
||||
version = "0.7.1"
|
||||
|
@ -11,7 +11,7 @@ license = "MIT"
|
||||
|
||||
[dependencies]
|
||||
# CLI interface
|
||||
clap = "3.2"
|
||||
clap = { version = "4.0", features = ["derive"] }
|
||||
|
||||
# Configuration
|
||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||
|
@ -12,7 +12,7 @@ use std::process;
|
||||
use std::str::FromStr;
|
||||
|
||||
use anyhow::Result;
|
||||
use clap::{App, Arg};
|
||||
use clap::{Parser, Subcommand};
|
||||
use tracing::Level;
|
||||
use tracing_subscriber::{filter, prelude::*};
|
||||
|
||||
@ -41,57 +41,41 @@ mod storage;
|
||||
mod test;
|
||||
mod uplink;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
struct Cli {
|
||||
/// Path to configuration directory
|
||||
#[arg(short, long, value_name = "DIR")]
|
||||
config: String,
|
||||
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
}
|
||||
|
||||
#[derive(Subcommand)]
|
||||
enum Commands {
|
||||
/// Print the configuration template
|
||||
Configfile {},
|
||||
|
||||
/// Print the device-session for debugging
|
||||
PrintDs {
|
||||
/// Device EUI
|
||||
#[arg(long, value_name = "DEV_EUI")]
|
||||
dev_eui: String,
|
||||
},
|
||||
|
||||
/// Import TheThingsNetwork LoRaWAN devices repository
|
||||
ImportTtnLorawanDevices {
|
||||
/// Path to repository root.
|
||||
#[arg(short, long, value_name = "DIR")]
|
||||
dir: String,
|
||||
},
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// read CLI
|
||||
let matches = App::new("chirpstack")
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
.author("Orne Brocaar <info@brocaar.com>")
|
||||
.about("ChirpStack open-source LoRaWAN network-server")
|
||||
.arg(
|
||||
Arg::with_name("config-dir")
|
||||
.required(true)
|
||||
.short('c')
|
||||
.long("config-dir")
|
||||
.value_name("DIR")
|
||||
.multiple(false)
|
||||
.number_of_values(1)
|
||||
.help("Path to configuration directory")
|
||||
.takes_value(true),
|
||||
)
|
||||
.subcommand(App::new("configfile").about("Print the configuration template"))
|
||||
.subcommand(
|
||||
App::new("print-ds")
|
||||
.about("Print the device-session for debugging")
|
||||
.arg(
|
||||
Arg::with_name("dev-eui")
|
||||
.required(true)
|
||||
.long("dev-eui")
|
||||
.value_name("DEV_EUI")
|
||||
.multiple(false)
|
||||
.help("Device EUI")
|
||||
.takes_value(true),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
App::new("import-ttn-lorawan-devices")
|
||||
.about("Import TheThingsNetwork LoRaWAN devices repository")
|
||||
.arg(
|
||||
Arg::with_name("dir")
|
||||
.required(true)
|
||||
.short('d')
|
||||
.long("dir")
|
||||
.value_name("DIR")
|
||||
.multiple(false)
|
||||
.number_of_values(1)
|
||||
.help("Path to repository root")
|
||||
.takes_value(true),
|
||||
),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
let config_dir = matches.get_one::<String>("config-dir").unwrap();
|
||||
config::load(Path::new(&config_dir))?;
|
||||
let cli = Cli::parse();
|
||||
config::load(Path::new(&cli.config))?;
|
||||
|
||||
let conf = config::get();
|
||||
let filter = filter::Targets::new().with_targets(vec![
|
||||
@ -105,22 +89,19 @@ async fn main() -> Result<()> {
|
||||
.with(filter)
|
||||
.init();
|
||||
|
||||
if matches.subcommand_matches("configfile").is_some() {
|
||||
if let Some(Commands::Configfile {}) = &cli.command {
|
||||
cmd::configfile::run();
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
if let Some(v) = matches.subcommand_matches("print-ds") {
|
||||
let dev_eui = v.get_one::<String>("dev-eui").unwrap();
|
||||
if let Some(Commands::PrintDs { dev_eui }) = &cli.command {
|
||||
let dev_eui = EUI64::from_str(dev_eui).unwrap();
|
||||
|
||||
cmd::print_ds::run(&dev_eui).await.unwrap();
|
||||
process::exit(0);
|
||||
}
|
||||
|
||||
if let Some(v) = matches.subcommand_matches("import-ttn-lorawan-devices") {
|
||||
let dir = v.get_one::<String>("dir").unwrap();
|
||||
cmd::import_ttn_lorawan_devices::run(Path::new(dir))
|
||||
if let Some(Commands::ImportTtnLorawanDevices { dir }) = &cli.command {
|
||||
cmd::import_ttn_lorawan_devices::run(Path::new(&dir))
|
||||
.await
|
||||
.unwrap();
|
||||
process::exit(0);
|
||||
|
Loading…
x
Reference in New Issue
Block a user