upgrade clap

This commit is contained in:
extrawurst 2022-11-14 14:57:30 +01:00
parent fbab49b858
commit b6ed33037e
3 changed files with 40 additions and 29 deletions

10
Cargo.lock generated
View file

@ -216,25 +216,23 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.2.22" version = "4.0.23"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" checksum = "0eb41c13df48950b20eb4cd0eefa618819469df1bffc49d11e8487c4ba0037e5"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
"clap_lex", "clap_lex",
"indexmap",
"once_cell", "once_cell",
"strsim", "strsim",
"termcolor", "termcolor",
"textwrap",
] ]
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.2.4" version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [ dependencies = [
"os_str_bytes", "os_str_bytes",
] ]

View file

@ -27,7 +27,7 @@ bitflags = "1.3"
bugreport = "0.5" bugreport = "0.5"
bytesize = { version = "1.1", default-features = false } bytesize = { version = "1.1", default-features = false }
chrono = { version = "0.4", default-features = false, features = [ "clock" ] } chrono = { version = "0.4", default-features = false, features = [ "clock" ] }
clap = { version = "3.2", features = [ "env", "cargo" ] } clap = { version = "4.0", features = [ "env", "cargo" ] }
crossbeam-channel = "0.5" crossbeam-channel = "0.5"
crossterm = { version = "0.25", features = [ "serde" ] } crossterm = { version = "0.25", features = [ "serde" ] }
dirs-next = "2.0" dirs-next = "2.0"

View file

@ -2,8 +2,8 @@ use crate::bug_report;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use asyncgit::sync::RepoPath; use asyncgit::sync::RepoPath;
use clap::{ use clap::{
crate_authors, crate_description, crate_name, crate_version, crate_authors, crate_description, crate_name, crate_version, Arg,
App as ClapApp, Arg, Command as ClapApp,
}; };
use simplelog::{Config, LevelFilter, WriteLogger}; use simplelog::{Config, LevelFilter, WriteLogger};
use std::{ use std::{
@ -21,17 +21,18 @@ pub fn process_cmdline() -> Result<CliArgs> {
let app = app(); let app = app();
let arg_matches = app.get_matches(); let arg_matches = app.get_matches();
if arg_matches.is_present("bugreport") { if arg_matches.contains_id("bugreport") {
bug_report::generate_bugreport(); bug_report::generate_bugreport();
std::process::exit(0); std::process::exit(0);
} }
if arg_matches.is_present("logging") { if arg_matches.contains_id("logging") {
setup_logging()?; setup_logging()?;
} }
let workdir = arg_matches.value_of("workdir").map(PathBuf::from); let workdir =
arg_matches.get_one::<String>("workdir").map(PathBuf::from);
let gitdir = arg_matches let gitdir = arg_matches
.value_of("directory") .get_one::<String>("directory")
.map_or_else(|| PathBuf::from("."), PathBuf::from); .map_or_else(|| PathBuf::from("."), PathBuf::from);
#[allow(clippy::option_if_let_else)] #[allow(clippy::option_if_let_else)]
@ -41,10 +42,11 @@ pub fn process_cmdline() -> Result<CliArgs> {
RepoPath::Path(gitdir) RepoPath::Path(gitdir)
}; };
let arg_theme = let arg_theme = arg_matches
arg_matches.value_of("theme").unwrap_or("theme.ron"); .get_one::<String>("theme")
.map_or_else(|| PathBuf::from("theme.ron"), PathBuf::from);
if get_app_config_path()?.join(arg_theme).is_file() { if get_app_config_path()?.join(&arg_theme).is_file() {
Ok(CliArgs { Ok(CliArgs {
theme: get_app_config_path()?.join(arg_theme), theme: get_app_config_path()?.join(arg_theme),
repo_path, repo_path,
@ -57,47 +59,58 @@ pub fn process_cmdline() -> Result<CliArgs> {
} }
} }
fn app() -> ClapApp<'static> { fn app() -> ClapApp {
let app = ClapApp::new(crate_name!()) ClapApp::new(crate_name!())
.author(crate_authors!()) .author(crate_authors!())
.version(crate_version!()) .version(crate_version!())
.about(crate_description!()) .about(crate_description!())
.help_template(
"\
{before-help}gitui {version}
{author}
{about}
{usage-heading} {usage}
{all-args}{after-help}
",
)
.arg( .arg(
Arg::with_name("theme") Arg::new("theme")
.help("Set the color theme (defaults to theme.ron)") .help("Set the color theme (defaults to theme.ron)")
.short('t') .short('t')
.long("theme") .long("theme")
.value_name("THEME") .value_name("THEME")
.takes_value(true), .num_args(1),
) )
.arg( .arg(
Arg::with_name("logging") Arg::new("logging")
.help("Stores logging output into a cache directory") .help("Stores logging output into a cache directory")
.short('l') .short('l')
.long("logging"), .long("logging")
.num_args(0),
) )
.arg( .arg(
Arg::with_name("bugreport") Arg::new("bugreport")
.help("Generate a bug report") .help("Generate a bug report")
.long("bugreport"), .long("bugreport"),
) )
.arg( .arg(
Arg::with_name("directory") Arg::new("directory")
.help("Set the git directory") .help("Set the git directory")
.short('d') .short('d')
.long("directory") .long("directory")
.env("GIT_DIR") .env("GIT_DIR")
.takes_value(true), .num_args(1),
) )
.arg( .arg(
Arg::with_name("workdir") Arg::new("workdir")
.help("Set the working directory") .help("Set the working directory")
.short('w') .short('w')
.long("workdir") .long("workdir")
.env("GIT_WORK_TREE") .env("GIT_WORK_TREE")
.takes_value(true), .num_args(1),
); )
app
} }
fn setup_logging() -> Result<()> { fn setup_logging() -> Result<()> {