Skip to content

Commit

Permalink
Fix more clap deprecation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred committed Jan 4, 2025
1 parent c286656 commit 5b76436
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,11 @@ fn parse_overrides_or_die(raw_overrides: &[String]) -> Vec<(LanguageOverride, Ve
pub(crate) fn parse_args() -> Mode {
let matches = app().get_matches();

let color_output = match matches.value_of("color").expect("color has a default") {
let color_output = match matches
.get_one::<String>("color")
.map(|s| s.as_str())
.expect("color has a default")
{
"always" => ColorOutput::Always,
"never" => ColorOutput::Never,
"auto" => ColorOutput::Auto,
Expand All @@ -659,8 +663,8 @@ pub(crate) fn parse_args() -> Mode {
let ignore_comments = matches.get_flag("ignore-comments");

let mut raw_overrides: Vec<String> = vec![];
if let Some(overrides) = matches.values_of("override") {
raw_overrides = overrides.map(|s| s.into()).collect();
if let Some(overrides) = matches.get_many("override") {
raw_overrides = overrides.cloned().collect();
}
for i in 1..=9 {
if let Ok(value) = env::var(format!("DFT_OVERRIDE_{}", i)) {
Expand All @@ -677,38 +681,42 @@ pub(crate) fn parse_args() -> Mode {
};
}

if let Some(path) = matches.value_of("dump-syntax") {
if let Some(path) = matches.get_one::<String>("dump-syntax") {
return Mode::DumpSyntax {
path: path.to_owned(),
ignore_comments,
language_overrides,
};
}

if let Some(path) = matches.value_of("dump-syntax-dot") {
if let Some(path) = matches.get_one::<String>("dump-syntax-dot") {
return Mode::DumpSyntaxDot {
path: path.to_owned(),
ignore_comments,
language_overrides,
};
}

if let Some(path) = matches.value_of("dump-ts") {
if let Some(path) = matches.get_one::<String>("dump-ts") {
return Mode::DumpTreeSitter {
path: path.to_owned(),
language_overrides,
};
}

let terminal_width = if let Some(arg_width) = matches.value_of("width") {
let terminal_width = if let Some(arg_width) = matches.get_one::<String>("width") {
arg_width
.parse::<usize>()
.expect("Already validated by clap")
} else {
detect_terminal_width()
};

let display_mode = match matches.value_of("display").expect("display has a default") {
let display_mode = match matches
.get_one::<String>("display")
.map(|s| s.as_str())
.expect("display has a default")
{
"side-by-side" => DisplayMode::SideBySide,
"side-by-side-show-both" => DisplayMode::SideBySideShowBoth,
"inline" => DisplayMode::Inline,
Expand All @@ -726,7 +734,8 @@ pub(crate) fn parse_args() -> Mode {
};

let background_color = match matches
.value_of("background")
.get_one::<String>("background")
.map(|s| s.as_str())
.expect("Always present as we've given clap a default")
{
"dark" => BackgroundColor::Dark,
Expand All @@ -742,31 +751,31 @@ pub(crate) fn parse_args() -> Mode {
let sort_paths = matches.get_flag("sort-paths");

let graph_limit = matches
.value_of("graph-limit")
.get_one::<String>("graph-limit")
.expect("Always present as we've given clap a default")
.parse::<usize>()
.expect("Value already validated by clap");

let byte_limit = matches
.value_of("byte-limit")
.get_one::<String>("byte-limit")
.expect("Always present as we've given clap a default")
.parse::<usize>()
.expect("Value already validated by clap");

let parse_error_limit = matches
.value_of("parse-error-limit")
.get_one::<String>("parse-error-limit")
.expect("Always present as we've given clap a default")
.parse::<usize>()
.expect("Value already validated by clap");

let tab_width = matches
.value_of("tab-width")
.get_one::<String>("tab-width")
.expect("Always present as we've given clap a default")
.parse::<usize>()
.expect("Value already validated by clap");

let num_context_lines = matches
.value_of("context")
.get_one::<String>("context")
.expect("Always present as we've given clap a default")
.parse::<u32>()
.expect("Value already validated by clap");
Expand Down

0 comments on commit 5b76436

Please sign in to comment.