Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix cargo audit issues #1137

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,010 changes: 509 additions & 501 deletions Cargo.lock

Large diffs are not rendered by default.

52 changes: 26 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@ lto = "thin"
panic = "abort"

[build-dependencies]
tera = "1.19.0"
ignore = "0.4.20"
serde_json = "1.0.104"
tera = "1.20.0"
ignore = "0.4.22"
serde_json = "1.0.125"
json5 = "0.4.1"

[dependencies]
aho-corasick = "1.0.2"
arbitrary = { version = "1.3.0", features = ["derive"] }
clap = { version = "3", features = ["cargo", "wrap_help"] }
colored = "2.0.4"
crossbeam-channel = "0.5.8"
aho-corasick = "1.1.3"
arbitrary = { version = "1.3.2", features = ["derive"] }
clap = { version = "4", features = ["cargo", "string", "wrap_help"] }
colored = "2.1.0"
crossbeam-channel = "0.5.13"
encoding_rs_io = "0.1.7"
grep-searcher = "0.1.11"
ignore = "0.4.20"
log = "0.4.19"
rayon = "1.7.0"
serde = { version = "1.0.180", features = ["derive", "rc"] }
grep-searcher = "0.1.13"
ignore = "0.4.22"
log = "0.4.22"
rayon = "1.10.0"
serde = { version = "1.0.208", features = ["derive", "rc"] }
term_size = "0.3.2"
toml = "0.7.6"
parking_lot = "0.12.1"
dashmap = { version = "5.5.0", features = ["serde"] }
toml = "0.8.19"
parking_lot = "0.12.3"
dashmap = { version = "6.0.1", features = ["serde"] }
num-format = "0.4.4"
once_cell = "1.18.0"
regex = "1.9.1"
serde_json = "1.0.104"
once_cell = "1.19.0"
regex = "1.10.6"
serde_json = "1.0.125"
etcetera = "0.8.0"
table_formatter = "0.6.1"

[dependencies.env_logger]
features = []
version = "0.10.0"
version = "0.11.5"

[dependencies.hex]
optional = true
Expand All @@ -74,11 +74,11 @@ version = "0.11.2"

[dependencies.serde_yaml]
optional = true
version = "0.9.25"
version = "0.9.34"

[dev-dependencies]
proptest = "1.2.0"
strum = "0.25.0"
strum_macros = "0.25.1"
tempfile = "3.7.0"
git2 = { version = "0.17.2", default-features = false, features = [] }
proptest = "1.5.0"
strum = "0.26.3"
strum_macros = "0.26.4"
tempfile = "3.12.0"
git2 = { version = "0.19.0", default-features = false, features = [] }
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extern crate ignore;
extern crate serde_json;
extern crate json5;
extern crate serde_json;

use std::ffi::OsStr;
use std::fs;
Expand Down
112 changes: 59 additions & 53 deletions src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::mem;
use std::process;

use clap::Arg;
use clap::{crate_description, ArgMatches};
use clap::{crate_description, value_parser, Arg, ArgAction, ArgMatches};
use colored::Colorize;
use tokei::{Config, LanguageType, Sort};

Expand Down Expand Up @@ -59,8 +57,8 @@ pub struct Cli {

impl Cli {
pub fn from_args() -> Self {
let matches = clap::App::new("tokei")
.version(&*crate_version())
let matches = clap::Command::new("tokei")
.version(crate_version())
.author("Erin P. <xampprocky@gmail.com> + Contributors")
.about(concat!(
crate_description!(),
Expand All @@ -71,7 +69,7 @@ impl Cli {
Arg::new("columns")
.long("columns")
.short('c')
.takes_value(true)
.value_parser(value_parser!(usize))
.conflicts_with("output")
.help(
"Sets a strict column width of the output, only available for \
Expand All @@ -82,8 +80,7 @@ impl Cli {
Arg::new("exclude")
.long("exclude")
.short('e')
.takes_value(true)
.multiple_values(true)
.num_args(0..)
.help("Ignore all files & directories matching the pattern."),
)
.arg(
Expand All @@ -96,7 +93,6 @@ impl Cli {
Arg::new("file_input")
.long("input")
.short('i')
.takes_value(true)
.help(
"Gives statistics from a previous tokei run. Can be given a file path, \
or \"stdin\" to read from stdin.",
Expand All @@ -109,7 +105,7 @@ impl Cli {
)
.arg(
Arg::new("input")
.min_values(1)
.num_args(1..)
.conflicts_with("languages")
.help("The path(s) to the file or directory to be counted.(default current directory)"),
)
Expand Down Expand Up @@ -140,8 +136,13 @@ impl Cli {
Arg::new("output")
.long("output")
.short('o')
.takes_value(true)
.possible_values(Format::all())
.value_parser(|x: &str| {
if Format::all().contains(&x) {
Ok(x.to_string())
} else {
Err(format!("Invalid output format: {x:?}"))
}
})
.help(
"Outputs Tokei in a specific format. Compile with additional features for \
more format support.",
Expand All @@ -150,8 +151,7 @@ impl Cli {
.arg(
Arg::new("streaming")
.long("streaming")
.takes_value(true)
.possible_values(["simple", "json"])
.value_parser(["simple", "json"])
.ignore_case(true)
.help(
"prints the (language, path, lines, blanks, code, comments) records as \
Expand All @@ -162,8 +162,7 @@ impl Cli {
Arg::new("sort")
.long("sort")
.short('s')
.takes_value(true)
.possible_values(["files", "lines", "blanks", "code", "comments"])
.value_parser(["files", "lines", "blanks", "code", "comments"])
.ignore_case(true)
.conflicts_with("rsort")
.help("Sort languages based on column"),
Expand All @@ -172,8 +171,7 @@ impl Cli {
Arg::new("rsort")
.long("rsort")
.short('r')
.takes_value(true)
.possible_values(["files", "lines", "blanks", "code", "comments"])
.value_parser(["files", "lines", "blanks", "code", "comments"])
.ignore_case(true)
.conflicts_with("sort")
.help("Reverse sort languages based on column"),
Expand All @@ -182,7 +180,7 @@ impl Cli {
Arg::new("types")
.long("types")
.short('t')
.takes_value(true)
.action(ArgAction::Append)
.help(
"Filters output by language type, separated by a comma. i.e. \
-t=Rust,Markdown",
Expand All @@ -198,8 +196,7 @@ impl Cli {
Arg::new("num_format_style")
.long("num-format")
.short('n')
.takes_value(true)
.possible_values(NumberFormatStyle::all())
.value_parser(["commas", "dots", "plain", "underscores"])
.conflicts_with("output")
.help(
"Format of printed numbers, i.e., plain (1234, default), \
Expand All @@ -211,7 +208,7 @@ impl Cli {
Arg::new("verbose")
.long("verbose")
.short('v')
.multiple_occurrences(true)
.action(ArgAction::Count)
.help(
"Set log output level:
1: to show unknown file extensions,
Expand All @@ -221,26 +218,29 @@ impl Cli {
)
.get_matches();

let columns = matches.value_of("columns").map(parse_or_exit::<usize>);
let files = matches.is_present("files");
let hidden = matches.is_present("hidden");
let no_ignore = matches.is_present("no_ignore");
let no_ignore_parent = matches.is_present("no_ignore_parent");
let no_ignore_dot = matches.is_present("no_ignore_dot");
let no_ignore_vcs = matches.is_present("no_ignore_vcs");
let print_languages = matches.is_present("languages");
let verbose = matches.occurrences_of("verbose");
let compact = matches.is_present("compact");
let types = matches.value_of("types").map(|e| {
e.split(',')
.map(str::parse::<LanguageType>)
.filter_map(Result::ok)
.collect()
let columns = matches.get_one::<usize>("columns").cloned();
let files = matches.get_flag("files");
let hidden = matches.get_flag("hidden");
let no_ignore = matches.get_flag("no_ignore");
let no_ignore_parent = matches.get_flag("no_ignore_parent");
let no_ignore_dot = matches.get_flag("no_ignore_dot");
let no_ignore_vcs = matches.get_flag("no_ignore_vcs");
let print_languages = matches.get_flag("languages");
let verbose = matches.get_count("verbose") as u64;
let compact = matches.get_flag("compact");
let types = matches.get_many("types").map(|e| {
e.flat_map(|x: &String| {
x.split(',')
.map(str::parse::<LanguageType>)
.filter_map(Result::ok)
.collect::<Vec<_>>()
})
.collect()
});

let num_format_style: NumberFormatStyle = matches
.value_of("num_format_style")
.map(parse_or_exit::<NumberFormatStyle>)
.get_one::<NumberFormatStyle>("num_format_style")
.cloned()
.unwrap_or_default();

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

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

// Format category is overly accepting by clap (so the user knows what
// is supported) but this will fail if support is not compiled in and
// give a useful error to the user.
let output = matches.value_of("output").map(parse_or_exit::<Format>);
let output = matches.get_one("output").cloned();
let streaming = matches
.value_of("streaming")
.get_one("streaming")
.cloned()
.map(parse_or_exit::<Streaming>);

crate::cli_utils::setup_logger(verbose);
Expand Down Expand Up @@ -295,20 +297,20 @@ impl Cli {
}

pub fn file_input(&self) -> Option<&str> {
self.matches.value_of("file_input")
self.matches.get_one("file_input").cloned()
}

pub fn ignored_directories(&self) -> Vec<&str> {
let mut ignored_directories: Vec<&str> = Vec::new();
if let Some(user_ignored) = self.matches.values_of("exclude") {
if let Some(user_ignored) = self.matches.get_many::<&str>("exclude") {
ignored_directories.extend(user_ignored);
}
ignored_directories
}

pub fn input(&self) -> Vec<&str> {
match self.matches.values_of("input") {
Some(vs) => vs.collect(),
match self.matches.get_many::<&str>("input") {
Some(vs) => vs.cloned().collect(),
None => vec!["."],
}
}
Expand All @@ -330,14 +332,18 @@ impl Cli {
padding = Padding::NONE,
width = Some(lang_w)
)
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(Colorize::bold)]),
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(
Colorize::bold,
)]),
cell!(
"Extensions",
align = Align::Left,
padding = Padding::new(3, 0),
width = Some(suffix_w)
)
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(Colorize::bold)]),
.with_formatter(vec![table_formatter::table::FormatterFunc::Normal(
Colorize::bold,
)]),
];
let content = LanguageType::list()
.iter()
Expand Down Expand Up @@ -429,7 +435,7 @@ impl Cli {
_ => None,
};

config.types = mem::replace(&mut self.types, None).or(config.types);
config.types = self.types.take().or(config.types);

config
}
Expand Down
3 changes: 1 addition & 2 deletions src/cli_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,7 @@ impl<W: Write> Printer<W> {

if self.list_files {
self.print_subrow()?;
let mut reports: Vec<&Report> =
language.reports.iter().map(|report| &*report).collect();
let mut reports: Vec<&Report> = language.reports.iter().collect();
if !is_sorted {
reports.sort_by(|&a, &b| a.name.cmp(&b.name));
}
Expand Down
1 change: 0 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ impl Config {
no_ignore_vcs: current_dir
.no_ignore_vcs
.or(home_dir.no_ignore_vcs.or(conf_dir.no_ignore_vcs)),
..Self::default()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ macro_rules! supported_formats {
///
/// To enable all formats compile with the `all` feature.
#[cfg_attr(test, derive(strum_macros::EnumIter))]
#[derive(Debug)]
#[derive(Debug, Clone)]
pub enum Format {
Json,
$(
Expand Down
Loading
Loading