Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

chore: update clap deprecations #1487

Merged
merged 10 commits into from
Feb 22, 2023
6 changes: 3 additions & 3 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2326,14 +2326,14 @@ impl IssueFilter {
}

pub fn get_filter_from_matches(matches: &ArgMatches) -> Result<IssueFilter> {
if matches.is_present("all") {
if matches.contains_id("all") {
return Ok(IssueFilter::All);
}
if let Some(status) = matches.value_of("status") {
if let Some(status) = matches.get_one::<String>("status") {
return Ok(IssueFilter::Status(status.into()));
}
let mut ids = vec![];
if let Some(values) = matches.values_of("id") {
if let Some(values) = matches.get_many::<String>("id") {
for value in values {
ids.push(value.parse::<u64>().context("Invalid issue ID")?);
}
Expand Down
32 changes: 17 additions & 15 deletions src/commands/bash_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,11 @@ fn send_event(traceback: &str, logfile: &str, environ: bool) -> Result<()> {
}

pub fn execute(matches: &ArgMatches) -> Result<()> {
if matches.is_present("send_event") {
if matches.contains_id("send_event") {
return send_event(
matches.value_of("traceback").unwrap(),
matches.value_of("log").unwrap(),
!matches.is_present("no_environ"),
matches.get_one::<String>("traceback").unwrap(),
matches.get_one::<String>("log").unwrap(),
!matches.contains_id("no_environ"),
);
}

Expand All @@ -192,22 +192,24 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
)
.replace("___SENTRY_LOG_FILE___", &log.display().to_string());

if matches.is_present("cli") {
script = script.replace("___SENTRY_CLI___", matches.value_of("cli").unwrap());
} else {
script = script.replace(
"___SENTRY_CLI___",
&env::current_exe().unwrap().display().to_string(),
);
}

if matches.is_present("no_environ") {
script = script.replace(
"___SENTRY_CLI___",
matches
.get_one::<String>("cli")
.map_or_else(
|| env::current_exe().unwrap().display().to_string(),
String::clone,
)
.as_str(),
);

if matches.contains_id("no_environ") {
script = script.replace("___SENTRY_NO_ENVIRON___", "--no-environ");
} else {
script = script.replace("___SENTRY_NO_ENVIRON___", "");
}

if !matches.is_present("no_exit") {
if !matches.contains_id("no_exit") {
script.insert_str(0, "set -e\n\n");
}
println!("{script}");
Expand Down
9 changes: 5 additions & 4 deletions src/commands/debug_files/bundle_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fs;
use std::path::{Path, PathBuf};

use anyhow::Result;
use clap::{Arg, ArgMatches, Command};
use clap::{Arg, ArgAction, ArgMatches, Command};
use log::warn;
use symbolic::debuginfo::sourcebundle::SourceBundleWriter;

Expand All @@ -15,7 +15,8 @@ pub fn make_command(command: Command) -> Command {
.arg(
Arg::new("paths")
.required(true)
.multiple_occurrences(true)
.multiple_values(true)
.action(ArgAction::Append)
.help("The path to the input debug info files."),
)
.arg(
Expand Down Expand Up @@ -67,9 +68,9 @@ fn get_canonical_path<P: AsRef<Path>>(path: P) -> Result<PathBuf> {
}

pub fn execute(matches: &ArgMatches) -> Result<()> {
let output_path = matches.value_of("output").map(Path::new);
let output_path = matches.get_one::<String>("output").map(Path::new);

for orig_path in matches.values_of("paths").unwrap() {
for orig_path in matches.get_many::<String>("paths").unwrap() {
let canonical_path = get_canonical_path(orig_path)?;

let archive = match DifFile::open_path(&canonical_path, None)? {
Expand Down
14 changes: 8 additions & 6 deletions src/commands/debug_files/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::io;
use std::path::Path;

use anyhow::Result;
use clap::{Arg, ArgMatches, Command};
use clap::{builder::PossibleValuesParser, Arg, ArgMatches, Command};
use console::style;

use crate::utils::dif::{DifFile, DifType};
Expand All @@ -26,7 +26,7 @@ pub fn make_command(command: Command) -> Command {
.long("type")
.short('t')
.value_name("TYPE")
.possible_values(DifType::all_names())
.value_parser(PossibleValuesParser::new(DifType::all_names()))
.help(
"Explicitly set the type of the debug info file. \
This should not be needed as files are auto detected.",
Expand All @@ -40,18 +40,20 @@ pub fn make_command(command: Command) -> Command {
}

pub fn execute(matches: &ArgMatches) -> Result<()> {
let path = Path::new(matches.value_of("path").unwrap());
let path = Path::new(matches.get_one::<String>("path").unwrap());

// which types should we consider?
let ty = matches.value_of("type").map(|t| t.parse().unwrap());
let ty = matches
.get_one::<String>("type")
.map(|t| t.parse().unwrap());
let dif = DifFile::open_path(path, ty)?;

if matches.is_present("json") {
if matches.contains_id("json") {
serde_json::to_writer_pretty(&mut io::stdout(), &dif)?;
println!();
}

if matches.is_present("json") || is_quiet_mode() {
if matches.contains_id("json") || is_quiet_mode() {
return if dif.is_usable() {
Ok(())
} else {
Expand Down
30 changes: 16 additions & 14 deletions src/commands/debug_files/find.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use std::collections::HashSet;
use std::env;
use std::ffi::OsStr;
use std::fmt::Debug;
use std::io;
use std::path::PathBuf;
use std::str::FromStr;

use anyhow::Result;
use clap::{Arg, ArgMatches, Command};
use clap::{builder::PossibleValuesParser, Arg, ArgAction, ArgMatches, Command};
use console::style;
use if_chain::if_chain;
use proguard::ProguardMapping;
Expand All @@ -14,7 +16,6 @@ use symbolic::common::{ByteView, DebugId};
use uuid::{Uuid, Version as UuidVersion};
use walkdir::{DirEntry, WalkDir};

use crate::utils::args::validate_id;
use crate::utils::dif::{DifFile, DifType};
use crate::utils::progress::{ProgressBar, ProgressStyle};
use crate::utils::system::QuietExit;
Expand All @@ -38,16 +39,17 @@ pub fn make_command(command: Command) -> Command {
Arg::new("ids")
.value_name("ID")
.help("The debug identifiers of the files to search for.")
.validator(validate_id)
.multiple_occurrences(true),
.value_parser(DebugId::from_str)
.multiple_values(true)
.action(ArgAction::Append),
)
.arg(
Arg::new("types")
.long("type")
.short('t')
.value_name("TYPE")
.multiple_occurrences(true)
.possible_values(DifType::all_names())
.action(ArgAction::Append)
.value_parser(PossibleValuesParser::new(DifType::all_names()))
.help(
"Only consider debug information files of the given \
type. By default all types are considered.",
Expand All @@ -68,7 +70,7 @@ pub fn make_command(command: Command) -> Command {
.long("path")
.short('p')
.value_name("PATH")
.multiple_occurrences(true)
.action(ArgAction::Append)
.help("Add a path to search recursively for debug info files."),
)
.arg(
Expand Down Expand Up @@ -329,16 +331,16 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
let mut ids = HashSet::new();

// which types should we consider?
if let Some(t) = matches.values_of("types") {
if let Some(t) = matches.get_many::<String>("types") {
for ty in t {
types.insert(ty.parse().unwrap());
}
} else {
types.extend(DifType::all());
}

let with_well_known = !matches.is_present("no_well_known");
let with_cwd = !matches.is_present("no_cwd");
let with_well_known = !matches.contains_id("no_well_known");
let with_cwd = !matches.contains_id("no_cwd");

// start adding well known locations
if_chain! {
Expand All @@ -361,22 +363,22 @@ pub fn execute(matches: &ArgMatches) -> Result<()> {
}

// extra paths
if let Some(p) = matches.values_of("paths") {
if let Some(p) = matches.get_many::<String>("paths") {
for path in p {
paths.insert(PathBuf::from(path));
}
}

// which ids are we looking for?
if let Some(i) = matches.values_of("ids") {
if let Some(i) = matches.get_many::<DebugId>("ids") {
for id in i {
ids.insert(id.parse().unwrap());
ids.insert(*id);
}
} else {
return Ok(());
}

if !find_ids(&paths, &types, &ids, matches.is_present("json"))? {
if !find_ids(&paths, &types, &ids, matches.contains_id("json"))? {
return Err(QuietExit(1).into());
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/debug_files/print_sources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn make_command(command: Command) -> Command {
}

pub fn execute(matches: &ArgMatches) -> Result<()> {
let path = Path::new(matches.value_of("path").unwrap());
let path = Path::new(matches.get_one::<String>("path").unwrap());

// which types should we consider?
let data = ByteView::open(path)?;
Expand Down