Replace structopt with clap

This commit is contained in:
Ivan Molodetskikh
2024-03-07 13:52:30 +04:00
parent ef75f3242f
commit e72558eba4
5 changed files with 228 additions and 190 deletions

View File

@@ -6,6 +6,7 @@
for copying. All internal uses of the function have been changed to simply
use `std::io::copy` instead.
- Replaced `nix` with `rustix`, following `wayland-rs`.
- Replaced the deprecated `structopt` with `clap` itself.
## v0.8.1 (7th Mar 2024)

335
Cargo.lock generated
View File

@@ -18,12 +18,51 @@ dependencies = [
]
[[package]]
name = "ansi_term"
version = "0.12.1"
name = "anstream"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb"
dependencies = [
"winapi",
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
]
[[package]]
@@ -32,17 +71,6 @@ version = "1.0.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1"
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi 0.1.19",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@@ -64,12 +92,6 @@ version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.2"
@@ -111,25 +133,56 @@ dependencies = [
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-targets",
"windows-targets 0.52.4",
]
[[package]]
name = "clap"
version = "2.34.0"
version = "4.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651"
dependencies = [
"ansi_term",
"atty",
"bitflags 1.3.2",
"strsim",
"term_size",
"textwrap",
"unicode-width",
"vec_map",
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
"terminal_size",
]
[[package]]
name = "clap_derive"
version = "4.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn 2.0.52",
]
[[package]]
name = "clap_lex"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce"
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "core-foundation-sys"
version = "0.8.6"
@@ -164,7 +217,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245"
dependencies = [
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@@ -204,21 +257,9 @@ checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "heck"
version = "0.3.3"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
dependencies = [
"libc",
]
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "hermit-abi"
@@ -271,9 +312,9 @@ version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f23ff5ef2b80d608d61efee834934d862cd92461afc0560dedf493e4c033738b"
dependencies = [
"hermit-abi 0.3.9",
"hermit-abi",
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@@ -304,7 +345,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
dependencies = [
"cfg-if",
"windows-targets",
"windows-targets 0.52.4",
]
[[package]]
@@ -395,7 +436,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57119c3b893986491ec9aa85056780d3a0f3cf4da7cc09dd3650dbd6c6738fb9"
dependencies = [
"libc",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@@ -420,30 +461,6 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[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.78"
@@ -461,7 +478,7 @@ checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf"
dependencies = [
"bit-set",
"bit-vec",
"bitflags 2.4.2",
"bitflags",
"lazy_static",
"num-traits",
"rand",
@@ -559,11 +576,11 @@ version = "0.38.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949"
dependencies = [
"bitflags 2.4.2",
"bitflags",
"errno",
"libc",
"linux-raw-sys",
"windows-sys",
"windows-sys 0.52.0",
]
[[package]]
@@ -605,33 +622,9 @@ dependencies = [
[[package]]
name = "strsim"
version = "0.8.0"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[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",
"proc-macro-error",
"proc-macro2",
"quote",
"syn 1.0.109",
]
checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01"
[[package]]
name = "syn"
@@ -664,17 +657,7 @@ dependencies = [
"cfg-if",
"fastrand",
"rustix",
"windows-sys",
]
[[package]]
name = "term_size"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9"
dependencies = [
"libc",
"winapi",
"windows-sys 0.52.0",
]
[[package]]
@@ -687,13 +670,13 @@ dependencies = [
]
[[package]]
name = "textwrap"
version = "0.11.0"
name = "terminal_size"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7"
dependencies = [
"term_size",
"unicode-width",
"rustix",
"windows-sys 0.48.0",
]
[[package]]
@@ -762,22 +745,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unicode-segmentation"
version = "1.11.0"
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
[[package]]
name = "unicode-width"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "version_check"
@@ -874,7 +845,7 @@ version = "0.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82fb96ee935c2cea6668ccb470fb7771f6215d1691746c2d896b447a00ad3f1f"
dependencies = [
"bitflags 2.4.2",
"bitflags",
"rustix",
"wayland-backend",
"wayland-scanner",
@@ -886,7 +857,7 @@ version = "0.31.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4"
dependencies = [
"bitflags 2.4.2",
"bitflags",
"wayland-backend",
"wayland-client",
"wayland-scanner",
@@ -899,7 +870,7 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6"
dependencies = [
"bitflags 2.4.2",
"bitflags",
"wayland-backend",
"wayland-client",
"wayland-protocols",
@@ -924,7 +895,7 @@ version = "0.31.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00e6e4d5c285bc24ba4ed2d5a4bd4febd5fd904451f465973225c8e99772fdb7"
dependencies = [
"bitflags 2.4.2",
"bitflags",
"downcast-rs",
"io-lifetimes",
"rustix",
@@ -983,7 +954,16 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9"
dependencies = [
"windows-targets",
"windows-targets 0.52.4",
]
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
@@ -992,7 +972,22 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets",
"windows-targets 0.52.4",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
@@ -1001,51 +996,93 @@ version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc",
"windows_aarch64_gnullvm 0.52.4",
"windows_aarch64_msvc 0.52.4",
"windows_i686_gnu 0.52.4",
"windows_i686_msvc 0.52.4",
"windows_x86_64_gnu 0.52.4",
"windows_x86_64_gnullvm 0.52.4",
"windows_x86_64_msvc 0.52.4",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.4"
@@ -1077,11 +1114,11 @@ name = "wl-clipboard-rs-tools"
version = "0.8.1"
dependencies = [
"anyhow",
"clap",
"libc",
"log",
"mime_guess",
"rustix",
"stderrlog",
"structopt",
"wl-clipboard-rs",
]

View File

@@ -13,12 +13,12 @@ categories = ["command-line-utilities"]
[dependencies]
anyhow = "1.0.80"
clap = { version = "4.5.2", features = ["derive", "wrap_help"] }
libc.workspace = true
log.workspace = true
mime_guess = "2.0.4"
rustix = { workspace = true, features = ["stdio"] }
stderrlog = "0.6.0"
structopt = { version = "0.3.26", features = ["wrap_help"] }
wl-clipboard-rs = { path = "../", version = "0.8.1" }
[features]

View File

@@ -2,17 +2,17 @@ use std::ffi::OsString;
use std::fs::OpenOptions;
use std::os::unix::ffi::OsStringExt;
use clap::Parser;
use libc::fork;
use rustix::stdio::{dup2_stdin, dup2_stdout};
use structopt::clap::AppSettings;
use structopt::StructOpt;
use wl_clipboard_rs::copy::{self, clear, ClipboardType, MimeType, Seat, ServeRequests, Source};
#[derive(StructOpt)]
#[structopt(name = "wl-copy",
about = "Copy clipboard contents on Wayland.",
rename_all = "kebab-case",
setting = AppSettings::ColoredHelp)]
#[derive(Parser)]
#[command(
name = "wl-copy",
version,
about = "Copy clipboard contents on Wayland."
)]
struct Options {
/// Serve only a single paste request and then exit
///
@@ -20,48 +20,48 @@ struct Options {
/// copying e.g. sensitive data, like passwords. Note however that certain apps may have issues
/// pasting when this option is used, in particular XWayland clients are known to suffer from
/// this.
#[structopt(long, short = "o", conflicts_with = "clear")]
#[arg(long, short = 'o', conflicts_with = "clear")]
paste_once: bool,
/// Stay in the foreground instead of forking
#[structopt(long, short, conflicts_with = "clear")]
#[arg(long, short, conflicts_with = "clear")]
foreground: bool,
/// Clear the clipboard instead of copying
#[structopt(long, short)]
#[arg(long, short)]
clear: bool,
/// Use the "primary" clipboard
///
/// Copying to the "primary" clipboard requires the compositor to support the data-control
/// protocol of version 2 or above.
#[structopt(long, short)]
#[arg(long, short)]
primary: bool,
/// Use the regular clipboard
///
/// Set this flag together with --primary to operate on both clipboards at once. Has no effect
/// otherwise (since the regular clipboard is the default clipboard).
#[structopt(long, short)]
#[arg(long, short)]
regular: bool,
/// Trim the trailing newline character before copying
///
/// This flag is only applied for text MIME types.
#[structopt(long, short = "n", conflicts_with = "clear")]
#[arg(long, short = 'n', conflicts_with = "clear")]
trim_newline: bool,
/// Pick the seat to work with
///
/// By default wl-copy operates on all seats at once.
#[structopt(long, short)]
#[arg(long, short)]
seat: Option<String>,
/// Override the inferred MIME type for the content
#[structopt(
name = "mime-type",
#[arg(
name = "MIME/TYPE",
long = "type",
short = "t",
short = 't',
conflicts_with = "clear"
)]
mime_type: Option<String>,
@@ -69,12 +69,12 @@ struct Options {
/// Text to copy
///
/// If not specified, wl-copy will use data from the standard input.
#[structopt(name = "text to copy", conflicts_with = "clear", parse(from_os_str))]
#[arg(name = "TEXT TO COPY", conflicts_with = "clear")]
text: Vec<OsString>,
/// Enable verbose logging
#[structopt(long, short, parse(from_occurrences))]
verbose: usize,
#[arg(long, short, action = clap::ArgAction::Count)]
verbose: u8,
}
impl From<Options> for copy::Options {
@@ -103,10 +103,10 @@ impl From<Options> for copy::Options {
fn main() -> Result<(), anyhow::Error> {
// Parse command-line options.
let mut options = Options::from_args();
let mut options = Options::parse();
stderrlog::new()
.verbosity(options.verbose.saturating_add(1))
.verbosity(usize::from(options.verbose) + 1)
.init()
.unwrap();

View File

@@ -4,35 +4,35 @@ use std::fs::read_link;
use std::io::{stdout, Read, Write};
use anyhow::Context;
use clap::Parser;
use libc::STDOUT_FILENO;
use log::trace;
use mime_guess::Mime;
use structopt::clap::AppSettings;
use structopt::StructOpt;
use wl_clipboard_rs::paste::*;
use wl_clipboard_rs::utils::is_text;
#[derive(StructOpt)]
#[structopt(name = "wl-paste",
about = "Paste clipboard contents on Wayland.",
rename_all = "kebab-case",
setting = AppSettings::ColoredHelp)]
#[derive(Parser)]
#[command(
name = "wl-paste",
version,
about = "Paste clipboard contents on Wayland."
)]
struct Options {
/// List the offered MIME types instead of pasting
#[structopt(long, short)]
#[arg(long, short)]
list_types: bool,
/// Use the "primary" clipboard
///
/// Pasting to the "primary" clipboard requires the compositor to support the data-control
/// protocol of version 2 or above.
#[structopt(long, short)]
#[arg(long, short)]
primary: bool,
/// Do not append a newline character
///
/// By default the newline character is appended automatically when pasting text MIME types.
#[structopt(long, short, conflicts_with = "list-types")]
#[arg(long, short, conflicts_with = "list-types")]
no_newline: bool,
/// Pick the seat to work with
@@ -40,24 +40,24 @@ struct Options {
/// By default the seat used is unspecified (it depends on the order returned by the
/// compositor). This is perfectly fine when only a single seat is present, so for most
/// configurations.
#[structopt(long, short)]
#[arg(long, short)]
seat: Option<String>,
/// Request the given MIME type instead of inferring the MIME type
///
/// As a special case, specifying "text" will look for a number of plain text types,
/// prioritizing ones that are known to give UTF-8 text.
#[structopt(
name = "mime-type",
#[arg(
name = "MIME/TYPE",
long = "type",
short = "t",
short = 't',
conflicts_with = "list-types"
)]
mime_type: Option<String>,
/// Enable verbose logging
#[structopt(long, short, parse(from_occurrences))]
verbose: usize,
#[arg(long, short, action = clap::ArgAction::Count)]
verbose: u8,
}
fn infer_mime_type() -> Option<Mime> {
@@ -70,7 +70,7 @@ fn infer_mime_type() -> Option<Mime> {
fn main() -> Result<(), anyhow::Error> {
// Parse command-line options.
let options = Options::from_args();
let options = Options::parse();
let primary = if options.primary {
ClipboardType::Primary
} else {
@@ -83,7 +83,7 @@ fn main() -> Result<(), anyhow::Error> {
.unwrap_or_default();
stderrlog::new()
.verbosity(options.verbose.saturating_add(1))
.verbosity(usize::from(options.verbose) + 1)
.init()
.unwrap();