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

View file

@ -27,7 +27,7 @@ bitflags = "1.3"
bugreport = "0.5"
bytesize = { version = "1.1", default-features = false }
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"
crossterm = { version = "0.25", features = [ "serde" ] }
dirs-next = "2.0"

View file

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