Skip to content

Commit b6ed330

Browse files
committed
upgrade clap
1 parent fbab49b commit b6ed330

File tree

3 files changed

+40
-29
lines changed

3 files changed

+40
-29
lines changed

Cargo.lock

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ bitflags = "1.3"
2727
bugreport = "0.5"
2828
bytesize = { version = "1.1", default-features = false }
2929
chrono = { version = "0.4", default-features = false, features = [ "clock" ] }
30-
clap = { version = "3.2", features = [ "env", "cargo" ] }
30+
clap = { version = "4.0", features = [ "env", "cargo" ] }
3131
crossbeam-channel = "0.5"
3232
crossterm = { version = "0.25", features = [ "serde" ] }
3333
dirs-next = "2.0"

src/args.rs

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use crate::bug_report;
22
use anyhow::{anyhow, Result};
33
use asyncgit::sync::RepoPath;
44
use clap::{
5-
crate_authors, crate_description, crate_name, crate_version,
6-
App as ClapApp, Arg,
5+
crate_authors, crate_description, crate_name, crate_version, Arg,
6+
Command as ClapApp,
77
};
88
use simplelog::{Config, LevelFilter, WriteLogger};
99
use std::{
@@ -21,17 +21,18 @@ pub fn process_cmdline() -> Result<CliArgs> {
2121
let app = app();
2222

2323
let arg_matches = app.get_matches();
24-
if arg_matches.is_present("bugreport") {
24+
if arg_matches.contains_id("bugreport") {
2525
bug_report::generate_bugreport();
2626
std::process::exit(0);
2727
}
28-
if arg_matches.is_present("logging") {
28+
if arg_matches.contains_id("logging") {
2929
setup_logging()?;
3030
}
3131

32-
let workdir = arg_matches.value_of("workdir").map(PathBuf::from);
32+
let workdir =
33+
arg_matches.get_one::<String>("workdir").map(PathBuf::from);
3334
let gitdir = arg_matches
34-
.value_of("directory")
35+
.get_one::<String>("directory")
3536
.map_or_else(|| PathBuf::from("."), PathBuf::from);
3637

3738
#[allow(clippy::option_if_let_else)]
@@ -41,10 +42,11 @@ pub fn process_cmdline() -> Result<CliArgs> {
4142
RepoPath::Path(gitdir)
4243
};
4344

44-
let arg_theme =
45-
arg_matches.value_of("theme").unwrap_or("theme.ron");
45+
let arg_theme = arg_matches
46+
.get_one::<String>("theme")
47+
.map_or_else(|| PathBuf::from("theme.ron"), PathBuf::from);
4648

47-
if get_app_config_path()?.join(arg_theme).is_file() {
49+
if get_app_config_path()?.join(&arg_theme).is_file() {
4850
Ok(CliArgs {
4951
theme: get_app_config_path()?.join(arg_theme),
5052
repo_path,
@@ -57,47 +59,58 @@ pub fn process_cmdline() -> Result<CliArgs> {
5759
}
5860
}
5961

60-
fn app() -> ClapApp<'static> {
61-
let app = ClapApp::new(crate_name!())
62+
fn app() -> ClapApp {
63+
ClapApp::new(crate_name!())
6264
.author(crate_authors!())
6365
.version(crate_version!())
6466
.about(crate_description!())
67+
.help_template(
68+
"\
69+
{before-help}gitui {version}
70+
{author}
71+
{about}
72+
73+
{usage-heading} {usage}
74+
75+
{all-args}{after-help}
76+
",
77+
)
6578
.arg(
66-
Arg::with_name("theme")
79+
Arg::new("theme")
6780
.help("Set the color theme (defaults to theme.ron)")
6881
.short('t')
6982
.long("theme")
7083
.value_name("THEME")
71-
.takes_value(true),
84+
.num_args(1),
7285
)
7386
.arg(
74-
Arg::with_name("logging")
87+
Arg::new("logging")
7588
.help("Stores logging output into a cache directory")
7689
.short('l')
77-
.long("logging"),
90+
.long("logging")
91+
.num_args(0),
7892
)
7993
.arg(
80-
Arg::with_name("bugreport")
94+
Arg::new("bugreport")
8195
.help("Generate a bug report")
8296
.long("bugreport"),
8397
)
8498
.arg(
85-
Arg::with_name("directory")
99+
Arg::new("directory")
86100
.help("Set the git directory")
87101
.short('d')
88102
.long("directory")
89103
.env("GIT_DIR")
90-
.takes_value(true),
104+
.num_args(1),
91105
)
92106
.arg(
93-
Arg::with_name("workdir")
107+
Arg::new("workdir")
94108
.help("Set the working directory")
95109
.short('w')
96110
.long("workdir")
97111
.env("GIT_WORK_TREE")
98-
.takes_value(true),
99-
);
100-
app
112+
.num_args(1),
113+
)
101114
}
102115

103116
fn setup_logging() -> Result<()> {

0 commit comments

Comments
 (0)