Skip to content

Commit 9627a24

Browse files
qtfkwkqtfkwk
andauthored
Fix cargo audit issues (#1137)
* run cargo outdated and cargo audit * run cargo upgrade -i && cargo update * apply fixes due to updating dependencies and running cargo clippy -- -D clippy::all * clean up; run cargo outdated/audit again; update; build; test * cargo fmt --------- Co-authored-by: qtfkwk <qtfkwk+tokei@gmail.com>
1 parent 9ad137f commit 9627a24

File tree

11 files changed

+653
-638
lines changed

11 files changed

+653
-638
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,37 +32,37 @@ lto = "thin"
3232
panic = "abort"
3333

3434
[build-dependencies]
35-
tera = "1.19.0"
36-
ignore = "0.4.20"
37-
serde_json = "1.0.104"
35+
tera = "1.20.0"
36+
ignore = "0.4.22"
37+
serde_json = "1.0.125"
3838
json5 = "0.4.1"
3939

4040
[dependencies]
41-
aho-corasick = "1.0.2"
42-
arbitrary = { version = "1.3.0", features = ["derive"] }
43-
clap = { version = "3", features = ["cargo", "wrap_help"] }
44-
colored = "2.0.4"
45-
crossbeam-channel = "0.5.8"
41+
aho-corasick = "1.1.3"
42+
arbitrary = { version = "1.3.2", features = ["derive"] }
43+
clap = { version = "4", features = ["cargo", "string", "wrap_help"] }
44+
colored = "2.1.0"
45+
crossbeam-channel = "0.5.13"
4646
encoding_rs_io = "0.1.7"
47-
grep-searcher = "0.1.11"
48-
ignore = "0.4.20"
49-
log = "0.4.19"
50-
rayon = "1.7.0"
51-
serde = { version = "1.0.180", features = ["derive", "rc"] }
47+
grep-searcher = "0.1.13"
48+
ignore = "0.4.22"
49+
log = "0.4.22"
50+
rayon = "1.10.0"
51+
serde = { version = "1.0.208", features = ["derive", "rc"] }
5252
term_size = "0.3.2"
53-
toml = "0.7.6"
54-
parking_lot = "0.12.1"
55-
dashmap = { version = "5.5.0", features = ["serde"] }
53+
toml = "0.8.19"
54+
parking_lot = "0.12.3"
55+
dashmap = { version = "6.0.1", features = ["serde"] }
5656
num-format = "0.4.4"
57-
once_cell = "1.18.0"
58-
regex = "1.9.1"
59-
serde_json = "1.0.104"
57+
once_cell = "1.19.0"
58+
regex = "1.10.6"
59+
serde_json = "1.0.125"
6060
etcetera = "0.8.0"
6161
table_formatter = "0.6.1"
6262

6363
[dependencies.env_logger]
6464
features = []
65-
version = "0.10.0"
65+
version = "0.11.5"
6666

6767
[dependencies.hex]
6868
optional = true
@@ -74,11 +74,11 @@ version = "0.11.2"
7474

7575
[dependencies.serde_yaml]
7676
optional = true
77-
version = "0.9.25"
77+
version = "0.9.34"
7878

7979
[dev-dependencies]
80-
proptest = "1.2.0"
81-
strum = "0.25.0"
82-
strum_macros = "0.25.1"
83-
tempfile = "3.7.0"
84-
git2 = { version = "0.17.2", default-features = false, features = [] }
80+
proptest = "1.5.0"
81+
strum = "0.26.3"
82+
strum_macros = "0.26.4"
83+
tempfile = "3.12.0"
84+
git2 = { version = "0.19.0", default-features = false, features = [] }

build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
extern crate ignore;
2-
extern crate serde_json;
32
extern crate json5;
3+
extern crate serde_json;
44

55
use std::ffi::OsStr;
66
use std::fs;

src/cli.rs

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::mem;
21
use std::process;
32

4-
use clap::Arg;
5-
use clap::{crate_description, ArgMatches};
3+
use clap::{crate_description, value_parser, Arg, ArgAction, ArgMatches};
64
use colored::Colorize;
75
use tokei::{Config, LanguageType, Sort};
86

@@ -59,8 +57,8 @@ pub struct Cli {
5957

6058
impl Cli {
6159
pub fn from_args() -> Self {
62-
let matches = clap::App::new("tokei")
63-
.version(&*crate_version())
60+
let matches = clap::Command::new("tokei")
61+
.version(crate_version())
6462
.author("Erin P. <xampprocky@gmail.com> + Contributors")
6563
.about(concat!(
6664
crate_description!(),
@@ -71,7 +69,7 @@ impl Cli {
7169
Arg::new("columns")
7270
.long("columns")
7371
.short('c')
74-
.takes_value(true)
72+
.value_parser(value_parser!(usize))
7573
.conflicts_with("output")
7674
.help(
7775
"Sets a strict column width of the output, only available for \
@@ -82,8 +80,7 @@ impl Cli {
8280
Arg::new("exclude")
8381
.long("exclude")
8482
.short('e')
85-
.takes_value(true)
86-
.multiple_values(true)
83+
.num_args(0..)
8784
.help("Ignore all files & directories matching the pattern."),
8885
)
8986
.arg(
@@ -96,7 +93,6 @@ impl Cli {
9693
Arg::new("file_input")
9794
.long("input")
9895
.short('i')
99-
.takes_value(true)
10096
.help(
10197
"Gives statistics from a previous tokei run. Can be given a file path, \
10298
or \"stdin\" to read from stdin.",
@@ -109,7 +105,7 @@ impl Cli {
109105
)
110106
.arg(
111107
Arg::new("input")
112-
.min_values(1)
108+
.num_args(1..)
113109
.conflicts_with("languages")
114110
.help("The path(s) to the file or directory to be counted.(default current directory)"),
115111
)
@@ -140,8 +136,13 @@ impl Cli {
140136
Arg::new("output")
141137
.long("output")
142138
.short('o')
143-
.takes_value(true)
144-
.possible_values(Format::all())
139+
.value_parser(|x: &str| {
140+
if Format::all().contains(&x) {
141+
Ok(x.to_string())
142+
} else {
143+
Err(format!("Invalid output format: {x:?}"))
144+
}
145+
})
145146
.help(
146147
"Outputs Tokei in a specific format. Compile with additional features for \
147148
more format support.",
@@ -150,8 +151,7 @@ impl Cli {
150151
.arg(
151152
Arg::new("streaming")
152153
.long("streaming")
153-
.takes_value(true)
154-
.possible_values(["simple", "json"])
154+
.value_parser(["simple", "json"])
155155
.ignore_case(true)
156156
.help(
157157
"prints the (language, path, lines, blanks, code, comments) records as \
@@ -162,8 +162,7 @@ impl Cli {
162162
Arg::new("sort")
163163
.long("sort")
164164
.short('s')
165-
.takes_value(true)
166-
.possible_values(["files", "lines", "blanks", "code", "comments"])
165+
.value_parser(["files", "lines", "blanks", "code", "comments"])
167166
.ignore_case(true)
168167
.conflicts_with("rsort")
169168
.help("Sort languages based on column"),
@@ -172,8 +171,7 @@ impl Cli {
172171
Arg::new("rsort")
173172
.long("rsort")
174173
.short('r')
175-
.takes_value(true)
176-
.possible_values(["files", "lines", "blanks", "code", "comments"])
174+
.value_parser(["files", "lines", "blanks", "code", "comments"])
177175
.ignore_case(true)
178176
.conflicts_with("sort")
179177
.help("Reverse sort languages based on column"),
@@ -182,7 +180,7 @@ impl Cli {
182180
Arg::new("types")
183181
.long("types")
184182
.short('t')
185-
.takes_value(true)
183+
.action(ArgAction::Append)
186184
.help(
187185
"Filters output by language type, separated by a comma. i.e. \
188186
-t=Rust,Markdown",
@@ -198,8 +196,7 @@ impl Cli {
198196
Arg::new("num_format_style")
199197
.long("num-format")
200198
.short('n')
201-
.takes_value(true)
202-
.possible_values(NumberFormatStyle::all())
199+
.value_parser(["commas", "dots", "plain", "underscores"])
203200
.conflicts_with("output")
204201
.help(
205202
"Format of printed numbers, i.e., plain (1234, default), \
@@ -211,7 +208,7 @@ impl Cli {
211208
Arg::new("verbose")
212209
.long("verbose")
213210
.short('v')
214-
.multiple_occurrences(true)
211+
.action(ArgAction::Count)
215212
.help(
216213
"Set log output level:
217214
1: to show unknown file extensions,
@@ -221,26 +218,29 @@ impl Cli {
221218
)
222219
.get_matches();
223220

224-
let columns = matches.value_of("columns").map(parse_or_exit::<usize>);
225-
let files = matches.is_present("files");
226-
let hidden = matches.is_present("hidden");
227-
let no_ignore = matches.is_present("no_ignore");
228-
let no_ignore_parent = matches.is_present("no_ignore_parent");
229-
let no_ignore_dot = matches.is_present("no_ignore_dot");
230-
let no_ignore_vcs = matches.is_present("no_ignore_vcs");
231-
let print_languages = matches.is_present("languages");
232-
let verbose = matches.occurrences_of("verbose");
233-
let compact = matches.is_present("compact");
234-
let types = matches.value_of("types").map(|e| {
235-
e.split(',')
236-
.map(str::parse::<LanguageType>)
237-
.filter_map(Result::ok)
238-
.collect()
221+
let columns = matches.get_one::<usize>("columns").cloned();
222+
let files = matches.get_flag("files");
223+
let hidden = matches.get_flag("hidden");
224+
let no_ignore = matches.get_flag("no_ignore");
225+
let no_ignore_parent = matches.get_flag("no_ignore_parent");
226+
let no_ignore_dot = matches.get_flag("no_ignore_dot");
227+
let no_ignore_vcs = matches.get_flag("no_ignore_vcs");
228+
let print_languages = matches.get_flag("languages");
229+
let verbose = matches.get_count("verbose") as u64;
230+
let compact = matches.get_flag("compact");
231+
let types = matches.get_many("types").map(|e| {
232+
e.flat_map(|x: &String| {
233+
x.split(',')
234+
.map(str::parse::<LanguageType>)
235+
.filter_map(Result::ok)
236+
.collect::<Vec<_>>()
237+
})
238+
.collect()
239239
});
240240

241241
let num_format_style: NumberFormatStyle = matches
242-
.value_of("num_format_style")
243-
.map(parse_or_exit::<NumberFormatStyle>)
242+
.get_one::<NumberFormatStyle>("num_format_style")
243+
.cloned()
244244
.unwrap_or_default();
245245

246246
let number_format = match num_format_style.get_format() {
@@ -253,18 +253,20 @@ impl Cli {
253253

254254
// Sorting category should be restricted by clap but parse before we do
255255
// work just in case.
256-
let sort = matches
257-
.value_of("sort")
258-
.or_else(|| matches.value_of("rsort"))
259-
.map(parse_or_exit::<Sort>);
260-
let sort_reverse = matches.value_of("rsort").is_some();
256+
let (sort, sort_reverse) = if let Some(sort) = matches.get_one::<Sort>("sort") {
257+
(Some(*sort), false)
258+
} else {
259+
let sort = matches.get_one::<Sort>("rsort");
260+
(sort.cloned(), sort.is_some())
261+
};
261262

262263
// Format category is overly accepting by clap (so the user knows what
263264
// is supported) but this will fail if support is not compiled in and
264265
// give a useful error to the user.
265-
let output = matches.value_of("output").map(parse_or_exit::<Format>);
266+
let output = matches.get_one("output").cloned();
266267
let streaming = matches
267-
.value_of("streaming")
268+
.get_one("streaming")
269+
.cloned()
268270
.map(parse_or_exit::<Streaming>);
269271

270272
crate::cli_utils::setup_logger(verbose);
@@ -295,20 +297,20 @@ impl Cli {
295297
}
296298

297299
pub fn file_input(&self) -> Option<&str> {
298-
self.matches.value_of("file_input")
300+
self.matches.get_one("file_input").cloned()
299301
}
300302

301303
pub fn ignored_directories(&self) -> Vec<&str> {
302304
let mut ignored_directories: Vec<&str> = Vec::new();
303-
if let Some(user_ignored) = self.matches.values_of("exclude") {
305+
if let Some(user_ignored) = self.matches.get_many::<&str>("exclude") {
304306
ignored_directories.extend(user_ignored);
305307
}
306308
ignored_directories
307309
}
308310

309311
pub fn input(&self) -> Vec<&str> {
310-
match self.matches.values_of("input") {
311-
Some(vs) => vs.collect(),
312+
match self.matches.get_many::<&str>("input") {
313+
Some(vs) => vs.cloned().collect(),
312314
None => vec!["."],
313315
}
314316
}
@@ -330,14 +332,18 @@ impl Cli {
330332
padding = Padding::NONE,
331333
width = Some(lang_w)
332334
)
333-
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(Colorize::bold)]),
335+
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(
336+
Colorize::bold,
337+
)]),
334338
cell!(
335339
"Extensions",
336340
align = Align::Left,
337341
padding = Padding::new(3, 0),
338342
width = Some(suffix_w)
339343
)
340-
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(Colorize::bold)]),
344+
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(
345+
Colorize::bold,
346+
)]),
341347
];
342348
let content = LanguageType::list()
343349
.iter()
@@ -429,7 +435,7 @@ impl Cli {
429435
_ => None,
430436
};
431437

432-
config.types = mem::replace(&mut self.types, None).or(config.types);
438+
config.types = self.types.take().or(config.types);
433439

434440
config
435441
}

src/cli_utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,7 @@ impl<W: Write> Printer<W> {
348348

349349
if self.list_files {
350350
self.print_subrow()?;
351-
let mut reports: Vec<&Report> =
352-
language.reports.iter().map(|report| &*report).collect();
351+
let mut reports: Vec<&Report> = language.reports.iter().collect();
353352
if !is_sorted {
354353
reports.sort_by(|&a, &b| a.name.cmp(&b.name));
355354
}

src/config.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ impl Config {
135135
no_ignore_vcs: current_dir
136136
.no_ignore_vcs
137137
.or(home_dir.no_ignore_vcs.or(conf_dir.no_ignore_vcs)),
138-
..Self::default()
139138
}
140139
}
141140
}

src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ macro_rules! supported_formats {
2929
///
3030
/// To enable all formats compile with the `all` feature.
3131
#[cfg_attr(test, derive(strum_macros::EnumIter))]
32-
#[derive(Debug)]
32+
#[derive(Debug, Clone)]
3333
pub enum Format {
3434
Json,
3535
$(

0 commit comments

Comments
 (0)