From 678ef58be60f2dc0c937bc8c3db824e28c4fd6ae Mon Sep 17 00:00:00 2001 From: kpcyrd Date: Mon, 2 Dec 2024 23:52:14 +0100 Subject: [PATCH] Port argument parsing from structopt (clap 2) to clap 4 --- Cargo.lock | 187 ++++++++++++++------------------------------- common/Cargo.toml | 7 +- common/src/lib.rs | 5 +- daemon/Cargo.toml | 2 +- daemon/src/main.rs | 15 ++-- tests/Cargo.toml | 2 +- tests/src/args.rs | 12 +-- tests/src/main.rs | 4 +- tools/Cargo.toml | 27 +++---- tools/src/args.rs | 124 +++++++++++++++--------------- tools/src/main.rs | 4 +- worker/Cargo.toml | 22 +++--- worker/src/args.rs | 31 ++++---- worker/src/main.rs | 4 +- 14 files changed, 192 insertions(+), 254 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e895864..ffbeb23 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f7b0a21988c1bf877cf4759ef5ddaac04c1c9fe808c9142ecb78ba97d97a28a" dependencies = [ - "bitflags 2.6.0", + "bitflags", "bytes", "futures-core", "futures-sink", @@ -31,7 +31,7 @@ dependencies = [ "actix-utils", "ahash", "base64 0.22.1", - "bitflags 2.6.0", + "bitflags", "brotli", "bytes", "bytestring", @@ -252,15 +252,6 @@ dependencies = [ "libc", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anstream" version = "0.6.18" @@ -377,12 +368,6 @@ version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.6.0" @@ -507,19 +492,53 @@ dependencies = [ [[package]] name = "clap" -version = "2.34.0" +version = "4.5.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +checksum = "fb3b4b9e5a7c7514dfa52869339ee98b3156b0bfb4e8a77c4ff4babb64b1604f" dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b17a95aa67cc7b5ebd32aa5370189aa0d79069ef1c64ce893bd30fb24bff20ec" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", ] +[[package]] +name = "clap_complete" +version = "4.5.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9647a559c112175f17cf724dc72d3645680a883c58481332779192b0d8e7a01" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.90", +] + +[[package]] +name = "clap_lex" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" + [[package]] name = "colorchoice" version = "1.0.3" @@ -617,7 +636,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim 0.11.1", + "strsim", "syn 2.0.90", ] @@ -1068,15 +1087,6 @@ version = "0.15.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.1" @@ -1549,7 +1559,7 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" dependencies = [ - "bitflags 2.6.0", + "bitflags", "libc", "redox_syscall", ] @@ -1703,7 +1713,7 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71e2746dc3a24dd78b3cfcb7be93368c6de9963d30f43a6a73998a9cf4b17b46" dependencies = [ - "bitflags 2.6.0", + "bitflags", "cfg-if", "cfg_aliases", "libc", @@ -1755,7 +1765,7 @@ version = "0.10.68" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6174bc48f102d208783c2c84bf931bb75927a617866870de8a4ea85597f871f5" dependencies = [ - "bitflags 2.6.0", + "bitflags", "cfg-if", "foreign-types", "libc", @@ -1896,30 +1906,6 @@ dependencies = [ "zerocopy", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.92" @@ -1986,6 +1972,8 @@ dependencies = [ "atty", "bzip2", "chrono", + "clap", + "clap_complete", "colored", "data-encoding", "dirs-next", @@ -1998,7 +1986,6 @@ dependencies = [ "reqwest", "serde", "serde_json", - "structopt", "tar", "tokio", "toml", @@ -2014,6 +2001,7 @@ version = "0.21.0" dependencies = [ "actix-web", "chrono", + "clap", "diesel", "diesel_migrations", "dirs-next", @@ -2024,7 +2012,6 @@ dependencies = [ "rebuilderd-common", "serde", "serde_json", - "structopt", "toml", ] @@ -2034,6 +2021,7 @@ version = "0.21.0" dependencies = [ "anyhow", "chrono", + "clap", "colored", "dirs-next", "log", @@ -2048,12 +2036,12 @@ name = "rebuilderd-tests" version = "0.21.0" dependencies = [ "actix-web", + "clap", "colored", "env_logger", "futures 0.3.31", "rebuilderd", "rebuilderd-common", - "structopt", "tempfile", "tokio", ] @@ -2063,6 +2051,7 @@ name = "rebuilderd-worker" version = "0.21.0" dependencies = [ "async-trait", + "clap", "data-encoding", "env_logger", "futures 0.3.31", @@ -2073,7 +2062,6 @@ dependencies = [ "reqwest", "serde", "serde_json", - "structopt", "tempfile", "tokio", "toml", @@ -2086,7 +2074,7 @@ version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" dependencies = [ - "bitflags 2.6.0", + "bitflags", ] [[package]] @@ -2232,7 +2220,7 @@ version = "0.38.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" dependencies = [ - "bitflags 2.6.0", + "bitflags", "errno", "libc", "linux-raw-sys", @@ -2329,7 +2317,7 @@ version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags 2.6.0", + "bitflags", "core-foundation", "core-foundation-sys", "libc", @@ -2474,42 +2462,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" -[[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck 0.3.3", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "strum" version = "0.24.1" @@ -2583,7 +2541,7 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c879d448e9d986b661742763247d3693ed13609438cf3d006f51f5368a5ba6b" dependencies = [ - "bitflags 2.6.0", + "bitflags", "core-foundation", "system-configuration-sys", ] @@ -2622,15 +2580,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.69" @@ -2846,18 +2795,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" -[[package]] -name = "unicode-segmentation" -version = "1.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" - -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - [[package]] name = "untrusted" version = "0.7.1" @@ -2905,12 +2842,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.5" diff --git a/common/Cargo.toml b/common/Cargo.toml index 9f1d05d..1b58df2 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -11,11 +11,12 @@ edition = "2021" [dependencies] anyhow = "1.0.58" -log = "0.4.17" -serde = { version="1.0.137", features=["derive"] } -reqwest = { version="0.12", features=["blocking", "json"] } chrono = { version = "0.4.19", features=["serde"] } +clap = "4.5.21" colored = "2.0.0" dirs-next = "2.0.0" +log = "0.4.17" +reqwest = { version="0.12", features=["blocking", "json"] } +serde = { version="1.0.137", features=["derive"] } toml = "0.8" url = "2.2.2" diff --git a/common/src/lib.rs b/common/src/lib.rs index 63df504..98d56f4 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -97,13 +97,16 @@ impl PkgGroup { } } -#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, clap::ValueEnum)] pub enum Status { #[serde(rename = "GOOD")] + #[clap(name = "GOOD")] Good, #[serde(rename = "BAD")] + #[clap(name = "BAD")] Bad, #[serde(rename = "UNKWN")] + #[clap(name = "UNKWN")] Unknown, } diff --git a/daemon/Cargo.toml b/daemon/Cargo.toml index f9e1e50..8f583c4 100644 --- a/daemon/Cargo.toml +++ b/daemon/Cargo.toml @@ -21,6 +21,7 @@ assets = [ [dependencies] actix-web = "4.1.0" chrono = { version = "0.4.19", features=["serde"] } +clap = { version = "4", features = ["derive"] } diesel = { version = "2", features = ["sqlite", "r2d2", "chrono", "i-implement-a-third-party-backend-and-opt-into-breaking-changes"] } diesel_migrations = { version = "2", features = ["sqlite"] } dirs-next = "2.0.0" @@ -31,7 +32,6 @@ rand = "0.8.5" rebuilderd-common = { version= "=0.21.0", path="../common" } serde = { version="1.0.137", features=["derive"] } serde_json = "1.0.81" -structopt = "0.3.26" toml = "0.8" # https://crates.io/crates/deb-version diff --git a/daemon/src/main.rs b/daemon/src/main.rs index 4a099dc..69a5d43 100644 --- a/daemon/src/main.rs +++ b/daemon/src/main.rs @@ -1,27 +1,26 @@ +use clap::{Parser, ArgAction}; use env_logger::Env; use std::path::PathBuf; -use structopt::StructOpt; -use structopt::clap::AppSettings; use rebuilderd::config; use rebuilderd_common::errors::*; -#[derive(Debug, StructOpt)] -#[structopt(global_settings = &[AppSettings::ColoredHelp])] +#[derive(Debug, Parser)] +#[command(version)] struct Args { /// Verbose logging - #[structopt(short, long, parse(from_occurrences))] + #[arg(short, long, action(ArgAction::Count))] verbose: u8, /// Load and print a config - #[structopt(long)] + #[arg(long)] check_config: bool, /// Configuration file path - #[structopt(short, long)] + #[arg(short, long)] config: Option, } #[actix_web::main] async fn main() -> Result<()> { - let args = Args::from_args(); + let args = Args::parse(); let logging = match args.verbose { 0 => "actix_web=debug,info", diff --git a/tests/Cargo.toml b/tests/Cargo.toml index 1a0f9d9..3ef449e 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -9,11 +9,11 @@ publish = false [dependencies] actix-web = "4.1.0" +clap = { version = "4", features = ["derive"] } colored = "2.0.0" env_logger = "0.11" futures = "0.3.21" rebuilderd = { version= "=0.21.0", path="../daemon" } rebuilderd-common = { version= "=0.21.0", path="../common" } -structopt = "0.3.26" tempfile = "3.3.0" tokio = { version="1.19.2", features=["macros", "rt-multi-thread"] } diff --git a/tests/src/args.rs b/tests/src/args.rs index a82e1d5..f2e8d58 100644 --- a/tests/src/args.rs +++ b/tests/src/args.rs @@ -1,16 +1,16 @@ -use structopt::StructOpt; +use clap::{Parser, ArgAction}; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Args { pub endpoint: Option, - #[structopt(short="b", default_value = "127.0.0.1:8484")] + #[arg(short = 'b', default_value = "127.0.0.1:8484")] pub bind_addr: String, - #[structopt(long)] + #[arg(long)] pub cookie: String, /// Verbose logging - #[structopt(short, long, parse(from_occurrences))] + #[arg(short, long, action(ArgAction::Count))] pub verbose: u8, /// Do not start a test daemon - #[structopt(long)] + #[arg(long)] pub no_daemon: bool, } diff --git a/tests/src/main.rs b/tests/src/main.rs index 5d7a08d..4e6b5e3 100644 --- a/tests/src/main.rs +++ b/tests/src/main.rs @@ -1,4 +1,5 @@ use crate::args::Args; +use clap::Parser; use colored::Colorize; use env_logger::Env; use rebuilderd::config::Config; @@ -12,7 +13,6 @@ use std::time::Duration; use std::io; use std::io::prelude::*; use std::net::TcpStream; -use structopt::StructOpt; use tempfile::TempDir; mod args; @@ -92,7 +92,7 @@ fn wait_for_server(addr: &str) -> Result<()> { #[tokio::main] async fn main() -> Result<()> { - let args = Args::from_args(); + let args = Args::parse(); let logging = match args.verbose { 0 => "warn,rebuilderd_tests=info", diff --git a/tools/Cargo.toml b/tools/Cargo.toml index 2baeb55..abf4689 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -16,28 +16,29 @@ assets = [ ] [dependencies] -rebuilderd-common = { version= "=0.21.0", path="../common" } -structopt = "0.3.26" -env_logger = "0.11" -reqwest = { version="0.12", features=["json"] } +atty = "0.2.14" +bzip2 = "0.4.3" chrono = { version = "0.4.19", features=["serde"] } -tar = "0.4.38" -flate2 = "1.0.24" -serde = { version="1.0.137", features=["derive"] } -serde_json = "1.0.81" +clap = { version = "4", features = ["derive"] } +clap_complete = "4.5.38" colored = "2.0.0" -toml = "0.8" dirs-next = "2.0.0" +env_logger = "0.11" +flate2 = "1.0.24" glob = "0.3.0" nom = "7.1.1" +rebuilderd-common = { version= "=0.21.0", path="../common" } +regex = "1.5.6" +reqwest = { version="0.12", features=["json"] } +serde = { version="1.0.137", features=["derive"] } +serde_json = "1.0.81" +tar = "0.4.38" tokio = { version="1.19.2", features=["macros", "rt-multi-thread", "io-std", "io-util"] } -atty = "0.2.14" +toml = "0.8" tree_magic_mini = "3.0.3" -bzip2 = "0.4.3" +url = "2.2.2" xz2 = "0.1" zstd = { version = "0.13", features = ["pkg-config"] } -regex = "1.5.6" -url = "2.2.2" [dev-dependencies] data-encoding = "2" diff --git a/tools/src/args.rs b/tools/src/args.rs index 3f18b6d..1ed1112 100644 --- a/tools/src/args.rs +++ b/tools/src/args.rs @@ -1,45 +1,45 @@ -#![allow(clippy::large_enum_variant)] - -use rebuilderd_common::Status; -use rebuilderd_common::errors::*; +use clap::{ArgAction, CommandFactory, Parser}; +use clap_complete::Shell; use glob::Pattern; -use std::io::stdout; +use rebuilderd_common::errors::*; +use rebuilderd_common::Status; +use std::io; use std::path::PathBuf; -use structopt::StructOpt; -use structopt::clap::{AppSettings, Shell}; -#[derive(Debug, StructOpt)] -#[structopt(global_settings = &[AppSettings::ColoredHelp])] +#[derive(Debug, Parser)] +#[command(version)] pub struct Args { /// Verbose logging - #[structopt(short, long, global = true, parse(from_occurrences))] + #[arg(short, long, global = true, action(ArgAction::Count))] pub verbose: u8, /// rebuilderd endpoint to talk to - #[structopt(short="H", long)] + #[arg(short = 'H', long)] pub endpoint: Option, /// Configuration file path - #[structopt(short, long)] + #[arg(short, long)] pub config: Option, /// Bypass tty detection and always use colors - #[structopt(short="C", long, global=true)] + #[arg(short = 'C', long, global = true)] pub color: bool, - #[structopt(subcommand)] + #[command(subcommand)] pub subcommand: SubCommand, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub enum SubCommand { /// Show worker status Status, /// Package related subcommands + #[command(subcommand)] Pkgs(Pkgs), /// Queue related subcommands + #[command(subcommand)] Queue(Queue), /// Generate shell completions Completions(Completions), } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub enum Pkgs { /// Sync package index Sync(PkgsSync), @@ -59,119 +59,119 @@ pub enum Pkgs { Attestation(PkgsAttestation), } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsSyncProfile { - #[structopt(long="print-json")] + #[arg(long)] pub print_json: bool, pub profile: String, - #[structopt(long="sync-config", default_value="/etc/rebuilderd-sync.conf")] + #[arg(long = "sync-config", default_value = "/etc/rebuilderd-sync.conf")] pub config_file: String, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsSyncStdin { pub distro: String, pub suite: String, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsSync { pub distro: String, pub suite: String, pub source: String, - #[structopt(long="architecture")] + #[arg(long = "architecture")] pub architectures: Vec, - #[structopt(long="print-json")] + #[arg(long)] pub print_json: bool, - #[structopt(long="maintainer")] + #[arg(long = "maintainer")] pub maintainers: Vec, - #[structopt(long="release")] + #[arg(long = "release")] pub releases: Vec, - #[structopt(long="pkg")] + #[arg(long = "pkg")] pub pkgs: Vec, - #[structopt(long="exclude")] + #[arg(long = "exclude")] pub excludes: Vec, - #[structopt(long)] + #[arg(long)] pub sync_method: Option, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsFilter { /// Filter packages matching this name - #[structopt(long)] + #[arg(long)] pub name: Option, /// Filter packages matching this status - #[structopt(long, possible_values=&["GOOD", "BAD", "UNKWN"])] + #[arg(long)] pub status: Option, /// Filter packages matching this distro - #[structopt(long)] + #[arg(long)] pub distro: Option, /// Filter packages matching this suite - #[structopt(long)] + #[arg(long)] pub suite: Option, /// Filter packages matching this architecture - #[structopt(long)] + #[arg(long)] pub architecture: Option, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsList { - #[structopt(flatten)] + #[command(flatten)] pub filter: PkgsFilter, - #[structopt(long)] + #[arg(long)] pub json: bool, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsRequeue { - #[structopt(flatten)] + #[command(flatten)] pub filter: PkgsFilter, /// Requeue with given priority - #[structopt(long, default_value="0")] + #[arg(long, default_value = "0")] pub priority: i32, /// Reset the status back to UNKWN - #[structopt(long)] + #[arg(long)] pub reset: bool, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsLog { - #[structopt(flatten)] + #[command(flatten)] pub filter: PkgsFilter, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsDiffoscope { - #[structopt(flatten)] + #[command(flatten)] pub filter: PkgsFilter, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct PkgsAttestation { - #[structopt(flatten)] + #[command(flatten)] pub filter: PkgsFilter, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub enum Queue { /// List the current build queue Ls(QueueList), /// Add a new task to the queue manually Push(QueuePush), /// Drop packages from queue matching given filter - #[structopt(name="drop")] + #[command(name = "drop")] Delete(QueueDrop), } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct QueueList { - #[structopt(long)] + #[arg(long)] pub head: bool, - #[structopt(long)] + #[arg(long)] pub json: bool, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct QueuePush { pub distro: String, pub suite: String, @@ -179,30 +179,34 @@ pub struct QueuePush { pub name: String, pub version: Option, - #[structopt(long)] + #[arg(long)] pub architecture: Option, - #[structopt(long, default_value="0")] + #[arg(long, default_value = "0")] pub priority: i32, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct QueueDrop { pub distro: String, pub suite: String, - #[structopt(long)] + #[arg(long)] pub architecture: Option, pub name: String, pub version: Option, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Completions { - #[structopt(possible_values=&Shell::variants())] pub shell: Shell, } pub fn gen_completions(args: &Completions) -> Result<()> { - Args::clap().gen_completions_to("rebuildctl", args.shell, &mut stdout()); + clap_complete::generate( + args.shell, + &mut Args::command(), + "rebuildctl", + &mut io::stdout(), + ); Ok(()) } diff --git a/tools/src/main.rs b/tools/src/main.rs index cbd7e8d..d064ba0 100644 --- a/tools/src/main.rs +++ b/tools/src/main.rs @@ -1,4 +1,5 @@ use colored::*; +use clap::Parser; use crate::args::*; use crate::config::SyncConfigFile; use env_logger::Env; @@ -11,7 +12,6 @@ use std::borrow::Cow; use std::fmt::Write as _; use std::io::prelude::*; use std::io; -use structopt::StructOpt; use tokio::io::AsyncReadExt; pub mod args; @@ -88,7 +88,7 @@ async fn fetch_build_id_by_filter(client: &Client, filter: PkgsFilter) -> Result #[tokio::main] async fn main() -> Result<()> { - let args = Args::from_args(); + let args = Args::parse(); let logging = match args.verbose { 0 => "info", diff --git a/worker/Cargo.toml b/worker/Cargo.toml index a8256ad..99e0d4f 100644 --- a/worker/Cargo.toml +++ b/worker/Cargo.toml @@ -18,19 +18,19 @@ assets = [ ] [dependencies] -rebuilderd-common = { version= "=0.21.0", path="../common" } -structopt = "0.3.26" -env_logger = "0.11" +async-trait = "0.1.56" +clap = { version = "4", features = ["derive", "env"] } data-encoding = "2" -toml = "0.8" +env_logger = "0.11" +futures = "0.3.21" +futures-util = "0.3.21" +in-toto = "0.3" +nix = { version = "0.29", features = ["process", "signal"] } +rebuilderd-common = { version= "=0.21.0", path="../common" } +reqwest = { version="0.12", features = ["stream"] } serde = { version="1.0.137", features=["derive"] } serde_json = "1.0.81" -reqwest = { version="0.12", features = ["stream"] } tempfile = "3.3.0" -url = "2.2.2" tokio = { version="1.19.2", features=["macros", "rt-multi-thread", "fs", "io-util", "process", "io-std", "time"] } -futures-util = "0.3.21" -futures = "0.3.21" -nix = { version = "0.29", features = ["process", "signal"] } -in-toto = "0.3" -async-trait = "0.1.56" +toml = "0.8" +url = "2.2.2" diff --git a/worker/src/args.rs b/worker/src/args.rs index 1bfb27a..9f83963 100644 --- a/worker/src/args.rs +++ b/worker/src/args.rs @@ -1,24 +1,23 @@ -use structopt::StructOpt; -use structopt::clap::AppSettings; +use clap::{Parser, ArgAction}; use std::path::PathBuf; -#[derive(Debug, StructOpt)] -#[structopt(global_settings = &[AppSettings::ColoredHelp])] +#[derive(Debug, Parser)] +#[command(version)] pub struct Args { /// Verbose logging - #[structopt(short, long, global = true, parse(from_occurrences))] + #[arg(short, long, global = true, action(ArgAction::Count))] pub verbose: u8, - #[structopt(subcommand)] + #[command(subcommand)] pub subcommand: SubCommand, - #[structopt(short, long)] + #[arg(short, long)] pub name: Option, - #[structopt(short, long, global = true, env = "REBUILDERD_WORKER_CONFIG")] + #[arg(short, long, global = true, env = "REBUILDERD_WORKER_CONFIG")] pub config: Option, - #[structopt(long="backend", global = true, env = "REBUILDERD_WORKER_BACKEND")] + #[arg(long = "backend", global = true, env = "REBUILDERD_WORKER_BACKEND")] pub backends: Vec, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub enum SubCommand { /// Rebuild an individual package Build(Build), @@ -30,29 +29,29 @@ pub enum SubCommand { CheckConfig, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Build { /// Selects the right build profile from the configuration pub distro: String, /// The pre-built artifact that should be reproduced pub artifact_url: String, /// Pass a different input file to the rebuilder backend - #[structopt(long)] + #[arg(long)] pub input_url: Option, /// Use a specific rebuilder script instead of the default - #[structopt(long)] + #[arg(long)] pub script_location: Option, /// Use diffoscope to generate a diff - #[structopt(long)] + #[arg(long)] pub gen_diffoscope: bool, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Connect { pub endpoint: Option, } -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct Diffoscope { pub a: PathBuf, pub b: PathBuf, diff --git a/worker/src/main.rs b/worker/src/main.rs index 928131d..3f246c5 100644 --- a/worker/src/main.rs +++ b/worker/src/main.rs @@ -1,11 +1,11 @@ #![recursion_limit="256"] use async_trait::async_trait; +use clap::Parser; use crate::args::{Args, SubCommand}; use crate::rebuild::Context; use env_logger::Env; use in_toto::crypto::PrivateKey; -use structopt::StructOpt; use rebuilderd_common::PkgArtifact; use rebuilderd_common::api::*; use rebuilderd_common::auth::find_auth_cookie; @@ -141,7 +141,7 @@ async fn run_worker_loop(client: &Client, privkey: &PrivateKey, config: &config: #[tokio::main] async fn main() -> Result<()> { - let args = Args::from_args(); + let args = Args::parse(); let logging = match args.verbose { 0 => "info",