Skip to content

Commit 70bd023

Browse files
committed
Replace unmaintained structopt with clap
1 parent f5ca89a commit 70bd023

File tree

4 files changed

+26
-24
lines changed

4 files changed

+26
-24
lines changed

obsctl/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ license = "MIT OR Apache-2.0"
1111
open-build-service-api = { path = "../open-build-service-api" }
1212
oscrc = { path = "../oscrc" }
1313
url = { version = "2.5.4", features = [ "serde" ] }
14-
structopt = "0.3.21"
1514
anyhow = "1.0.40"
1615
tokio = { version = "1.35.0", features = [ "full" ] }
16+
clap = { version = "4.5.28", features = ["derive"] }
17+
clap_derive = "4.5.28"

obsctl/src/main.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use anyhow::{bail, Context, Result};
2+
use clap::Parser;
23
use open_build_service_api::{Client, PackageCode, ResultListResult};
34
use oscrc::Oscrc;
45
use std::path::PathBuf;
56
use std::time::Duration;
6-
use structopt::StructOpt;
77
use url::Url;
88

9-
#[derive(StructOpt, Debug)]
9+
#[derive(Parser, Debug)]
1010
struct Package {
1111
project: String,
1212
package: String,
@@ -84,28 +84,28 @@ async fn monitor(client: Client, opts: Package) -> Result<()> {
8484
Ok(())
8585
}
8686

87-
#[derive(StructOpt, Debug)]
87+
#[derive(Parser, Debug)]
8888
enum Command {
8989
Monitor(Package),
9090
}
9191

92-
#[derive(StructOpt)]
92+
#[derive(Parser, Debug)]
9393
struct Opts {
94-
#[structopt(long, short)]
94+
#[arg(long, short)]
9595
apiurl: Option<Url>,
96-
#[structopt(long, short, default_value = "/home/sjoerd/.oscrc")]
96+
#[arg(long, short, default_value = "/home/sjoerd/.oscrc")]
9797
config: PathBuf,
98-
#[structopt(long, short, requires("pass"))]
98+
#[arg(long, short, requires = "pass")]
9999
user: Option<String>,
100-
#[structopt(long, short, requires("user"))]
100+
#[arg(long, short, requires = "user")]
101101
pass: Option<String>,
102-
#[structopt(subcommand)]
102+
#[command(subcommand)]
103103
command: Command,
104104
}
105105

106106
#[tokio::main]
107107
async fn main() -> Result<()> {
108-
let opts = Opts::from_args();
108+
let opts = Opts::parse();
109109
let (url, user, pass) = match opts {
110110
Opts {
111111
apiurl: Some(url),

open-build-service-api/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ strum_macros = "0.23"
2424
open-build-service-mock = { path = "../open-build-service-mock" }
2525
oscrc = { path = "../oscrc" }
2626
url = { version = "2.5.4", features = [ "serde" ] }
27-
structopt = "0.3.21"
27+
clap = { version = "4.5.28", features = ["derive"] }
28+
clap_derive = "4.5.28"
2829
anyhow = "1.0.40"
2930
tokio = { version = "1.35.0", features = [ "full" ] }

open-build-service-api/examples/obsapi.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
use anyhow::{Context, Result};
2+
use clap::Parser;
23
use futures::prelude::*;
34
use open_build_service_api::{Client, PackageLogStreamOptions};
45
use oscrc::Oscrc;
56
use std::path::PathBuf;
6-
use structopt::StructOpt;
77
use tokio::io::AsyncWriteExt;
88
use url::Url;
99

10-
#[derive(StructOpt, Debug)]
10+
#[derive(Parser, Debug)]
1111
struct PackageFull {
1212
project: String,
1313
package: String,
1414
repository: String,
1515
arch: String,
1616
}
1717

18-
#[derive(StructOpt, Debug)]
18+
#[derive(Parser, Debug)]
1919
struct Package {
2020
project: String,
2121
package: String,
2222
}
2323

24-
#[derive(StructOpt, Debug)]
24+
#[derive(Parser, Debug)]
2525
struct BuildResult {
2626
project: String,
2727
package: Option<String>,
@@ -80,7 +80,7 @@ async fn result(client: Client, opts: BuildResult) -> Result<()> {
8080
Ok(())
8181
}
8282

83-
#[derive(StructOpt, Debug)]
83+
#[derive(Parser, Debug)]
8484
enum Command {
8585
Jobstatus(PackageFull),
8686
History(PackageFull),
@@ -90,23 +90,23 @@ enum Command {
9090
Result(BuildResult),
9191
}
9292

93-
#[derive(StructOpt)]
93+
#[derive(Parser)]
9494
struct Opts {
95-
#[structopt(long, short)]
95+
#[arg(long, short)]
9696
apiurl: Option<Url>,
97-
#[structopt(long, short, default_value = "/home/sjoerd/.oscrc")]
97+
#[arg(long, short, default_value = "/home/sjoerd/.oscrc")]
9898
config: PathBuf,
99-
#[structopt(long, short, requires("pass"))]
99+
#[arg(long, short, requires = "pass")]
100100
user: Option<String>,
101-
#[structopt(long, short, requires("user"))]
101+
#[arg(long, short, requires = "user")]
102102
pass: Option<String>,
103-
#[structopt(subcommand)]
103+
#[command(subcommand)]
104104
command: Command,
105105
}
106106

107107
#[tokio::main]
108108
async fn main() -> Result<()> {
109-
let opts = Opts::from_args();
109+
let opts = Opts::parse();
110110
let (url, user, pass) = match opts {
111111
Opts {
112112
apiurl: Some(url),

0 commit comments

Comments
 (0)