Skip to content

Commit 4e7cc80

Browse files
Fix clap deprecations
1 parent 3ad9499 commit 4e7cc80

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

collector/benchlib/src/cli.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::{FromArgMatches, IntoApp};
1+
use clap::{CommandFactory, FromArgMatches};
22

33
#[derive(clap::Parser, Debug)]
44
pub enum Args {
@@ -24,7 +24,7 @@ pub struct BenchmarkArgs {
2424
}
2525

2626
pub fn parse_cli() -> anyhow::Result<Args> {
27-
let app = Args::into_app();
27+
let app = Args::command();
2828

2929
// Set the name of the help to the current binary name
3030
let app = app.name(

collector/src/bin/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ struct LocalOptions {
497497
id: Option<String>,
498498

499499
/// The path to the local Cargo to use
500-
#[clap(long, parse(from_os_str))]
500+
#[clap(long, value_parser)]
501501
cargo: Option<PathBuf>,
502502

503503
/// Exclude all benchmarks matching a prefix in this comma-separated list
@@ -531,7 +531,7 @@ struct CompileTimeOptions {
531531
scenarios: ScenarioArg,
532532

533533
/// The path to the local rustdoc to measure
534-
#[clap(long, parse(from_os_str))]
534+
#[clap(long, value_parser)]
535535
rustdoc: Option<PathBuf>,
536536
}
537537

database/src/bin/postgres-to-sqlite.rs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! transactions, and will likely fail if used on a populated database.
55
66
use chrono::{DateTime, Utc};
7+
use clap::{builder::PossibleValuesParser, ArgAction};
78
use database::pool::{postgres, sqlite, ConnectionManager};
89
use futures::StreamExt;
910
use rusqlite::params;
@@ -462,37 +463,42 @@ async fn main() -> anyhow::Result<()> {
462463

463464
let table_names: Vec<_> = tables.iter().map(|table| table.name()).collect();
464465

465-
let matches = clap::App::new("postgres-to-sqlite")
466+
let matches = clap::Command::new("postgres-to-sqlite")
466467
.about("Exports a rustc-perf Postgres database to a SQLite database")
467468
.version(clap::crate_version!())
468469
.arg(
469470
clap::Arg::new("exclude-tables")
471+
.action(ArgAction::Set)
470472
.long("exclude-tables")
471-
.takes_value(true)
472473
.value_name("TABLES")
473-
.possible_values(&table_names)
474-
.use_delimiter(true)
474+
.value_parser(PossibleValuesParser::new(table_names))
475+
.takes_value(true)
476+
.use_value_delimiter(true)
475477
.help("Exclude given tables (as foreign key constraints allow)"),
476478
)
477479
.arg(
478480
clap::Arg::new("no-self-profile")
481+
.action(ArgAction::SetTrue)
479482
.long("no-self-profile")
480483
.help("Exclude some potentially large self-profile tables (additive with --exclude-tables)"),
481484
)
482485
.arg(
483486
clap::Arg::new("since-weeks-ago")
487+
.action(ArgAction::Set)
484488
.long("since-weeks-ago")
485489
.takes_value(true)
486490
.value_name("WEEKS")
487491
.help("Exclude data associated with artifacts whose date value precedes <WEEKS> weeks ago"),
488492
)
489493
.arg(
490494
clap::Arg::new("fast-unsafe")
495+
.action(ArgAction::SetTrue)
491496
.long("fast-unsafe")
492497
.help("Enable faster execution at the risk of corrupting SQLite database in the event of a crash"),
493498
)
494499
.arg(
495500
clap::Arg::new("postgres-db")
501+
.action(ArgAction::Set)
496502
.required(true)
497503
.value_name("POSTGRES_DB")
498504
.help(
@@ -502,31 +508,29 @@ async fn main() -> anyhow::Result<()> {
502508
)
503509
.arg(
504510
clap::Arg::new("sqlite-db")
511+
.action(ArgAction::Set)
505512
.required(true)
506513
.value_name("SQLITE_DB")
507514
.help("SQLite database file"),
508515
)
509516
.get_matches();
510517

511-
let postgres = matches.value_of("postgres-db").unwrap();
512-
let sqlite = matches.value_of("sqlite-db").unwrap();
518+
let postgres = matches.get_one::<String>("postgres-db").unwrap();
519+
let sqlite = matches.get_one::<String>("sqlite-db").unwrap();
513520

514521
let mut exclude_tables: std::collections::HashSet<_> = matches
515-
.values_of("exclude-tables")
522+
.get_many::<String>("exclude-tables")
516523
.unwrap_or_default()
524+
.cloned()
517525
.collect();
518526

519-
if matches.is_present("no-self-profile") {
520-
exclude_tables.insert(SelfProfileQuerySeries.name());
521-
exclude_tables.insert(SelfProfileQuery.name());
527+
if matches.get_flag("no-self-profile") {
528+
exclude_tables.insert(SelfProfileQuerySeries.name().to_owned());
529+
exclude_tables.insert(SelfProfileQuery.name().to_owned());
522530
// `RawSelfProfile` is intentionally kept.
523531
}
524532

525-
let since_weeks_ago = match matches.value_of_t("since-weeks-ago") {
526-
Ok(weeks) => Some(weeks),
527-
Err(err) if err.kind == clap::ErrorKind::ArgumentNotFound => None,
528-
Err(err) => err.exit(),
529-
};
533+
let since_weeks_ago = matches.get_one::<u32>("since-weeks-ago").copied();
530534

531535
let mut postgres: tokio_postgres::Client =
532536
postgres::Postgres::new(postgres.into()).open().await.into();
@@ -537,7 +541,7 @@ async fn main() -> anyhow::Result<()> {
537541
.into_inner()
538542
.unwrap();
539543

540-
if matches.is_present("fast-unsafe") {
544+
if matches.get_flag("fast-unsafe") {
541545
sqlite.pragma_update(None, "journal_mode", &"OFF").unwrap();
542546
sqlite.pragma_update(None, "synchronous", &"OFF").unwrap();
543547
}
@@ -558,7 +562,7 @@ async fn main() -> anyhow::Result<()> {
558562
let sqlite_tx = sqlite.transaction().unwrap();
559563

560564
for &table in tables {
561-
if !exclude_tables.contains(&table.name()) {
565+
if !exclude_tables.contains(table.name()) {
562566
copy(table, &postgres_tx, &sqlite_tx, since_weeks_ago).await;
563567
}
564568
}

database/src/bin/sqlite-to-postgres.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'a> TryFrom<rusqlite::types::ValueRef<'a>> for Nullable<&'a str> {
616616
async fn main() -> anyhow::Result<()> {
617617
env_logger::init();
618618

619-
let matches = clap::App::new("sqlite-to-postgres")
619+
let matches = clap::Command::new("sqlite-to-postgres")
620620
.about("Exports a rustc-perf SQLite database to a Postgres database")
621621
.version(clap::crate_version!())
622622
.arg(
@@ -636,8 +636,8 @@ async fn main() -> anyhow::Result<()> {
636636
)
637637
.get_matches();
638638

639-
let postgres = matches.value_of("postgres-db").unwrap();
640-
let sqlite = matches.value_of("sqlite-db").unwrap();
639+
let postgres = matches.get_one::<String>("postgres-db").unwrap();
640+
let sqlite = matches.get_one::<String>("sqlite-db").unwrap();
641641

642642
let mut sqlite = sqlite::Sqlite::new(sqlite.into())
643643
.open()

0 commit comments

Comments
 (0)