Skip to content

Commit b888928

Browse files
fowlesfacebook-github-bot
authored andcommitted
chore: upgrade from structopt to clap
Summary: structopt is in maintence mode and explicitly refers to clap as the successor. Modernize examples a bit and switch names to match the clap examples. X-link: facebook/watchman#1224 Reviewed By: chadaustin Differential Revision: D58486829 Pulled By: genevievehelsel fbshipit-source-id: 9c1c1ed7a0da7badd62fa098b6f2d3a90061d0aa
1 parent 02462c0 commit b888928

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

third-party/watchman/src/watchman/rust/watchman_client/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ thiserror = "1.0"
2020
tokio = { version = "1.7.1", features = ["full", "test-util"] }
2121
tokio-util = { version = "0.6", features = ["full"] }
2222

23-
[dev-dependencies]
24-
structopt = "0.3"
25-
2623
[target.'cfg(windows)'.dependencies]
2724
winapi = { version = "0.3", features = ["handleapi", "winuser"] }
25+
26+
[dev-dependencies]
27+
clap = { version = "4.5.7", features = ["derive"] }

third-party/watchman/src/watchman/rust/watchman_client/examples/glob.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
use std::path::PathBuf;
99

10+
use clap::Parser;
1011
use serde::Deserialize;
11-
use structopt::StructOpt;
1212
use watchman_client::prelude::*;
1313

14-
#[derive(Debug, StructOpt)]
15-
#[structopt(about = "Perform a glob query for a path, using watchman")]
16-
struct Opt {
17-
#[structopt(default_value = ".")]
14+
/// Perform a glob query for a path, using watchman
15+
#[derive(Debug, Parser)]
16+
struct Cli {
17+
#[arg(default_value = ".")]
1818
path: PathBuf,
1919
}
2020

@@ -29,7 +29,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2929
}
3030

3131
async fn run() -> Result<(), Box<dyn std::error::Error>> {
32-
let opt = Opt::from_args();
32+
let opt = Cli::parse();
3333
let client = Connector::new().connect().await?;
3434
let resolved = client
3535
.resolve_root(CanonicalPath::canonicalize(opt.path)?)

third-party/watchman/src/watchman/rust/watchman_client/examples/since.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,21 @@
1010
1111
use std::path::PathBuf;
1212

13-
use structopt::StructOpt;
13+
use clap::Parser;
1414
use watchman_client::prelude::*;
1515

16-
#[derive(Debug, StructOpt)]
17-
#[structopt(about = "Query files changed since a timestamp")]
18-
struct Opt {
19-
#[structopt()]
20-
/// Specifies the clock. Use `watchman clock <PATH>` to retrieve the current clock of a watched
21-
/// directory
16+
/// Query files changed since a timestamp
17+
#[derive(Debug, Parser)]
18+
struct Cli {
19+
/// Specifies the clock. Use `watchman clock <PATH>` to retrieve the current
20+
/// clock of a watched directory
2221
clock: String,
2322

24-
#[structopt(short, long)]
23+
#[arg(short, long)]
2524
/// [not recommended] Uses Unix timestamp as clock
2625
unix_timestamp: bool,
2726

28-
#[structopt(short, long, default_value = ".")]
27+
#[arg(short, long, default_value = ".")]
2928
/// Specifies the path to watched directory
3029
path: PathBuf,
3130
}
@@ -41,7 +40,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4140
}
4241

4342
async fn run() -> Result<(), Box<dyn std::error::Error>> {
44-
let opt = Opt::from_args();
43+
let opt = Cli::parse();
4544
let client = Connector::new().connect().await?;
4645
let resolved = client
4746
.resolve_root(CanonicalPath::canonicalize(opt.path)?)

third-party/watchman/src/watchman/rust/watchman_client/examples/state.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77

88
use std::path::PathBuf;
99

10-
use structopt::StructOpt;
10+
use clap::Parser;
1111
use watchman_client::prelude::*;
1212

13-
#[derive(Debug, StructOpt)]
14-
#[structopt(about = "Exercise the state-enter and state-leave commands")]
15-
struct Opt {
16-
#[structopt(default_value = ".")]
13+
/// Exercise the state-enter and state-leave commands
14+
#[derive(Debug, Parser)]
15+
struct Cli {
16+
#[arg(default_value = ".")]
1717
path: PathBuf,
1818
}
1919

@@ -28,7 +28,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2828
}
2929

3030
async fn run() -> Result<(), Box<dyn std::error::Error>> {
31-
let opt = Opt::from_args();
31+
let opt = Cli::parse();
3232
let client = Connector::new().connect().await?;
3333
let resolved = client
3434
.resolve_root(CanonicalPath::canonicalize(opt.path)?)

third-party/watchman/src/watchman/rust/watchman_client/examples/subscribe.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
//! file changes as they are reported
1010
use std::path::PathBuf;
1111

12-
use structopt::StructOpt;
12+
use clap::Parser;
1313
use watchman_client::prelude::*;
1414

15-
#[derive(Debug, StructOpt)]
16-
#[structopt(about = "Subscribe to watchman and stream file changes for a path")]
17-
struct Opt {
18-
#[structopt(default_value = ".")]
15+
/// Subscribe to watchman and stream file changes for a path
16+
#[derive(Debug, Parser)]
17+
struct Cli {
18+
#[arg(default_value = ".")]
1919
path: PathBuf,
2020
}
2121

@@ -29,7 +29,7 @@ async fn main() {
2929
}
3030

3131
async fn run() -> Result<(), Box<dyn std::error::Error>> {
32-
let opt = Opt::from_args();
32+
let opt = Cli::parse();
3333
let client = Connector::new().connect().await?;
3434
let resolved = client
3535
.resolve_root(CanonicalPath::canonicalize(opt.path)?)

0 commit comments

Comments
 (0)