refactor: Un-nest code. Use clap-derive. (#122)

This commit is contained in:
Samuel Åkesson
2026-02-05 22:15:52 +01:00
committed by GitHub
parent 584873698c
commit ef159d7e3c
2 changed files with 13 additions and 22 deletions

View File

@@ -1,17 +1,9 @@
use clap::Parser;
use std::path::PathBuf;
use clap::{Command, arg, crate_description, crate_name, crate_version, value_parser};
pub fn cli() -> Command {
Command::new(crate_name!())
.about(crate_description!())
.version(crate_version!())
.arg(
arg!(--config <config>)
.short('c')
.id("config")
.required(false)
.help("Config file path")
.value_parser(value_parser!(PathBuf)),
)
#[derive(Parser)]
#[command(version, about)]
pub struct Args {
#[arg(short, long)]
pub config_path: Option<PathBuf>,
}

View File

@@ -7,23 +7,22 @@ use bluetui::{
rfkill,
tui::Tui,
};
use clap::Parser;
use ratatui::{Terminal, backend::CrosstermBackend};
use std::{io, path::PathBuf, process::exit, sync::Arc};
use std::{io, process::exit, sync::Arc};
#[tokio::main]
async fn main() -> AppResult<()> {
let args = cli::cli().get_matches();
let args = cli::Args::parse();
let config_file_path = if let Some(config) = args.get_one::<PathBuf>("config") {
if config.exists() {
Some(config.to_owned())
let config_file_path = args.config_path.map(|config_path| {
if config_path.exists() {
config_path.to_owned()
} else {
eprintln!("Config file not found");
exit(1);
}
} else {
None
};
});
rfkill::check()?;