Update to clap 4

This commit is contained in:
AsamK 2022-10-09 12:30:25 +02:00
parent 58bb4b5358
commit 94d79692df
4 changed files with 169 additions and 129 deletions

94
client/Cargo.lock generated
View file

@ -55,6 +55,12 @@ version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
[[package]]
name = "cc"
version = "1.0.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -63,26 +69,25 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "3.2.22"
version = "4.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
checksum = "4ed45cc2c62a3eff523e718d8576ba762c83a3146151093283ac62ae11933a73"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_lex",
"indexmap",
"once_cell",
"strsim",
"termcolor",
"textwrap",
"terminal_size",
]
[[package]]
name = "clap_derive"
version = "3.2.18"
version = "4.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65"
checksum = "db342ce9fda24fb191e2ed4e102055a4d381c1086a06630174cd8da8d5d917ce"
dependencies = [
"heck",
"proc-macro-error",
@ -93,9 +98,9 @@ dependencies = [
[[package]]
name = "clap_lex"
version = "0.2.4"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8"
dependencies = [
"os_str_bytes",
]
@ -119,6 +124,27 @@ dependencies = [
"syn",
]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -246,12 +272,6 @@ dependencies = [
"regex",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888"
[[package]]
name = "heck"
version = "0.4.0"
@ -267,16 +287,6 @@ dependencies = [
"libc",
]
[[package]]
name = "indexmap"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
dependencies = [
"autocfg",
"hashbrown",
]
[[package]]
name = "instant"
version = "0.1.12"
@ -286,6 +296,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "io-lifetimes"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ea37f355c05dde75b84bba2d767906ad522e97cd9e2eef2be7a4ab7fb442c06"
[[package]]
name = "itoa"
version = "1.0.4"
@ -420,6 +436,12 @@ version = "0.2.134"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb"
[[package]]
name = "linux-raw-sys"
version = "0.0.46"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4d2456c373231a208ad294c33dc5bff30051eafd954cd4caae83a712b12854d"
[[package]]
name = "lock_api"
version = "0.4.9"
@ -663,6 +685,20 @@ dependencies = [
"semver",
]
[[package]]
name = "rustix"
version = "0.35.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbb2fda4666def1433b1b05431ab402e42a1084285477222b72d6c564c417cef"
dependencies = [
"bitflags",
"errno",
"io-lifetimes",
"libc",
"linux-raw-sys",
"windows-sys",
]
[[package]]
name = "ryu"
version = "1.0.11"
@ -781,10 +817,14 @@ dependencies = [
]
[[package]]
name = "textwrap"
version = "0.15.1"
name = "terminal_size"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1"
dependencies = [
"rustix",
"windows-sys",
]
[[package]]
name = "tokio"

View file

@ -7,7 +7,7 @@ edition = "2021"
[dependencies]
anyhow = "1"
clap = { version = "3", features = ["cargo", "derive"] }
clap = { version = "4", features = ["cargo", "derive", "wrap_help"] }
jsonrpc-core = "18"
jsonrpc-core-client = "18"
jsonrpc-client-transports = { version = "18", default-features = false, features = [

View file

@ -1,34 +1,34 @@
use clap::{crate_version, ArgEnum, Parser, Subcommand};
use clap::{crate_version, Parser, Subcommand, ValueEnum};
use std::{ffi::OsString, net::SocketAddr};
/// JSON-RPC client for signal-cli
#[derive(Parser, Debug)]
#[clap(rename_all = "kebab-case", version=crate_version!())]
#[command(rename_all = "kebab-case", version=crate_version!())]
pub struct Cli {
/// Account to use (for daemon in multi-account mode)
#[clap(short = 'a', long)]
#[arg(short = 'a', long)]
pub account: Option<String>,
/// TCP host and port of signal-cli daemon
#[clap(long)]
#[arg(long)]
pub json_rpc_tcp: Option<Option<SocketAddr>>,
/// UNIX socket address and port of signal-cli daemon
#[clap(long)]
#[arg(long)]
pub json_rpc_socket: Option<Option<OsString>>,
#[clap(arg_enum, long, default_value_t = OutputTypes::Json)]
#[arg(value_enum, long, default_value_t = OutputTypes::Json)]
pub output: OutputTypes,
#[clap(long)]
#[arg(long)]
pub verbose: bool,
#[clap(subcommand)]
#[command(subcommand)]
pub command: CliCommands,
}
#[derive(ArgEnum, Clone, Debug)]
#[clap(rename_all = "kebab-case")]
#[derive(ValueEnum, Clone, Debug)]
#[value(rename_all = "kebab-case")]
pub enum OutputTypes {
PlainText,
Json,
@ -36,181 +36,181 @@ pub enum OutputTypes {
#[allow(clippy::large_enum_variant)]
#[derive(Subcommand, Debug)]
#[clap(rename_all = "camelCase", version=crate_version!())]
#[command(rename_all = "camelCase", version=crate_version!())]
pub enum CliCommands {
AddDevice {
#[clap(long)]
#[arg(long)]
uri: String,
},
#[clap(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")]
Block {
recipient: Vec<String>,
#[clap(short = 'g', long)]
#[arg(short = 'g', long)]
group_id: Vec<String>,
},
DeleteLocalAccountData {
#[clap(long = "ignore-registered")]
#[arg(long = "ignore-registered")]
ignore_registered: Option<bool>,
},
GetUserStatus {
recipient: Vec<String>,
},
JoinGroup {
#[clap(long)]
#[arg(long)]
uri: String,
},
Link {
#[clap(short = 'n', long)]
#[arg(short = 'n', long)]
name: String,
},
ListAccounts,
ListContacts {
recipient: Vec<String>,
#[clap(short = 'a', long = "all-recipients")]
#[arg(short = 'a', long = "all-recipients")]
all_recipients: bool,
#[clap(long)]
#[arg(long)]
blocked: Option<bool>,
#[clap(long)]
#[arg(long)]
name: Option<String>,
},
ListDevices,
ListGroups {
#[clap(short = 'd', long)]
#[arg(short = 'd', long)]
detailed: bool,
#[clap(short = 'g', long = "group-id")]
#[arg(short = 'g', long = "group-id")]
group_id: Vec<String>,
},
ListIdentities {
#[clap(short = 'n', long)]
#[arg(short = 'n', long)]
number: Option<String>,
},
ListStickerPacks,
QuitGroup {
#[clap(short = 'g', long = "group-id")]
#[arg(short = 'g', long = "group-id")]
group_id: String,
#[clap(long)]
#[arg(long)]
delete: bool,
#[clap(long)]
#[arg(long)]
admin: Vec<String>,
},
Receive {
#[clap(short = 't', long, default_value_t = 3.0)]
#[arg(short = 't', long, default_value_t = 3.0)]
timeout: f64,
},
Register {
#[clap(short = 'v', long)]
#[arg(short = 'v', long)]
voice: bool,
#[clap(long)]
#[arg(long)]
captcha: Option<String>,
},
RemoveContact {
recipient: String,
#[clap(long)]
#[arg(long)]
forget: bool,
},
RemoveDevice {
#[clap(short = 'd', long = "device-id")]
#[arg(short = 'd', long = "device-id")]
device_id: u32,
},
RemovePin,
RemoteDelete {
#[clap(short = 't', long = "target-timestamp")]
#[arg(short = 't', long = "target-timestamp")]
target_timestamp: u64,
recipient: Vec<String>,
#[clap(short = 'g', long = "group-id")]
#[arg(short = 'g', long = "group-id")]
group_id: Vec<String>,
#[clap(long = "note-to-self")]
#[arg(long = "note-to-self")]
note_to_self: bool,
},
#[clap(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")]
Send {
recipient: Vec<String>,
#[clap(short = 'g', long)]
#[arg(short = 'g', long)]
group_id: Vec<String>,
#[clap(long)]
#[arg(long)]
note_to_self: bool,
#[clap(short = 'e', long)]
#[arg(short = 'e', long)]
end_session: bool,
#[clap(short = 'm', long)]
#[arg(short = 'm', long)]
message: Option<String>,
#[clap(short = 'a', long)]
#[arg(short = 'a', long)]
attachment: Vec<String>,
#[clap(long)]
#[arg(long)]
mention: Vec<String>,
#[clap(long)]
#[arg(long)]
quote_timestamp: Option<u64>,
#[clap(long)]
#[arg(long)]
quote_author: Option<String>,
#[clap(long)]
#[arg(long)]
quote_message: Option<String>,
#[clap(long)]
#[arg(long)]
quote_mention: Vec<String>,
#[clap(long)]
#[arg(long)]
sticker: Option<String>,
},
SendContacts,
SendPaymentNotification {
recipient: String,
#[clap(long)]
#[arg(long)]
receipt: String,
#[clap(long)]
#[arg(long)]
note: String,
},
SendReaction {
recipient: Vec<String>,
#[clap(short = 'g', long = "group-id")]
#[arg(short = 'g', long = "group-id")]
group_id: Vec<String>,
#[clap(long = "note-to-self")]
#[arg(long = "note-to-self")]
note_to_self: bool,
#[clap(short = 'e', long)]
#[arg(short = 'e', long)]
emoji: String,
#[clap(short = 'a', long = "target-author")]
#[arg(short = 'a', long = "target-author")]
target_author: String,
#[clap(short = 't', long = "target-timestamp")]
#[arg(short = 't', long = "target-timestamp")]
target_timestamp: u64,
#[clap(short = 'r', long)]
#[arg(short = 'r', long)]
remove: bool,
},
SendReceipt {
recipient: String,
#[clap(short = 't', long = "target-timestamp")]
#[arg(short = 't', long = "target-timestamp")]
target_timestamp: Vec<u64>,
#[clap(arg_enum, long)]
#[arg(value_enum, long)]
r#type: ReceiptType,
},
SendSyncRequest,
SendTyping {
recipient: Vec<String>,
#[clap(short = 'g', long = "group-id")]
#[arg(short = 'g', long = "group-id")]
group_id: Vec<String>,
#[clap(short = 's', long)]
#[arg(short = 's', long)]
stop: bool,
},
SetPin {
@ -223,118 +223,118 @@ pub enum CliCommands {
Trust {
recipient: String,
#[clap(short = 'a', long = "trust-all-known-keys")]
#[arg(short = 'a', long = "trust-all-known-keys")]
trust_all_known_keys: bool,
#[clap(short = 'v', long = "verified-safety-number")]
#[arg(short = 'v', long = "verified-safety-number")]
verified_safety_number: Option<String>,
},
#[clap(rename_all = "kebab-case")]
#[command(rename_all = "kebab-case")]
Unblock {
recipient: Vec<String>,
#[clap(short = 'g', long)]
#[arg(short = 'g', long)]
group_id: Vec<String>,
},
Unregister {
#[clap(long = "delete-account")]
#[arg(long = "delete-account")]
delete_account: bool,
},
UpdateAccount {
#[clap(short = 'n', long = "device-name")]
#[arg(short = 'n', long = "device-name")]
device_name: Option<String>,
},
UpdateConfiguration {
#[clap(long = "read-receipts")]
#[arg(long = "read-receipts")]
read_receipts: Option<bool>,
#[clap(long = "unidentified-delivery-indicators")]
#[arg(long = "unidentified-delivery-indicators")]
unidentified_delivery_indicators: Option<bool>,
#[clap(long = "typing-indicators")]
#[arg(long = "typing-indicators")]
typing_indicators: Option<bool>,
#[clap(long = "link-previews")]
#[arg(long = "link-previews")]
link_previews: Option<bool>,
},
UpdateContact {
recipient: String,
#[clap(short = 'e', long)]
#[arg(short = 'e', long)]
expiration: Option<u32>,
#[clap(short = 'n', long)]
#[arg(short = 'n', long)]
name: Option<String>,
},
UpdateGroup {
#[clap(short = 'g', long = "group-id")]
#[arg(short = 'g', long = "group-id")]
group_id: Option<String>,
#[clap(short = 'n', long)]
#[arg(short = 'n', long)]
name: Option<String>,
#[clap(short = 'd', long)]
#[arg(short = 'd', long)]
description: Option<String>,
#[clap(short = 'a', long)]
#[arg(short = 'a', long)]
avatar: Option<String>,
#[clap(short = 'm', long)]
#[arg(short = 'm', long)]
member: Vec<String>,
#[clap(short = 'r', long = "remove-member")]
#[arg(short = 'r', long = "remove-member")]
remove_member: Vec<String>,
#[clap(long)]
#[arg(long)]
admin: Vec<String>,
#[clap(long = "remove-admin")]
#[arg(long = "remove-admin")]
remove_admin: Vec<String>,
#[clap(long)]
#[arg(long)]
ban: Vec<String>,
#[clap(long)]
#[arg(long)]
unban: Vec<String>,
#[clap(long = "reset-link")]
#[arg(long = "reset-link")]
reset_link: bool,
#[clap(arg_enum, long)]
#[arg(value_enum, long)]
link: Option<LinkState>,
#[clap(arg_enum, long = "set-permission-add-member")]
#[arg(value_enum, long = "set-permission-add-member")]
set_permission_add_member: Option<GroupPermission>,
#[clap(arg_enum, long = "set-permission-edit-details")]
#[arg(value_enum, long = "set-permission-edit-details")]
set_permission_edit_details: Option<GroupPermission>,
#[clap(arg_enum, long = "set-permission-send-messages")]
#[arg(value_enum, long = "set-permission-send-messages")]
set_permission_send_messages: Option<GroupPermission>,
#[clap(short = 'e', long)]
#[arg(short = 'e', long)]
expiration: Option<u32>,
},
UpdateProfile {
#[clap(long = "given-name")]
#[arg(long = "given-name")]
given_name: Option<String>,
#[clap(long = "family-name")]
#[arg(long = "family-name")]
family_name: Option<String>,
#[clap(long)]
#[arg(long)]
about: Option<String>,
#[clap(long = "about-emoji")]
#[arg(long = "about-emoji")]
about_emoji: Option<String>,
#[clap(long = "mobile-coin-address")]
#[arg(long = "mobile-coin-address")]
mobile_coin_address: Option<String>,
#[clap(long)]
#[arg(long)]
avatar: Option<String>,
#[clap(long = "remove-avatar")]
#[arg(long = "remove-avatar")]
remove_avatar: bool,
},
UploadStickerPack {
@ -343,29 +343,29 @@ pub enum CliCommands {
Verify {
verification_code: String,
#[clap(short = 'p', long)]
#[arg(short = 'p', long)]
pin: Option<String>,
},
Version,
}
#[derive(ArgEnum, Clone, Debug)]
#[clap(rename_all = "kebab-case")]
#[derive(ValueEnum, Clone, Debug)]
#[value(rename_all = "kebab-case")]
pub enum ReceiptType {
Read,
Viewed,
}
#[derive(ArgEnum, Clone, Debug)]
#[clap(rename_all = "kebab-case")]
#[derive(ValueEnum, Clone, Debug)]
#[value(rename_all = "kebab-case")]
pub enum LinkState {
Enabled,
EnabledWithApproval,
Disabled,
}
#[derive(ArgEnum, Clone, Debug)]
#[clap(rename_all = "kebab-case")]
#[derive(ValueEnum, Clone, Debug)]
#[value(rename_all = "kebab-case")]
pub enum GroupPermission {
EveryMember,
OnlyAdmins,

View file

@ -1,4 +1,4 @@
use clap::StructOpt;
use clap::Parser;
use jsonrpc_client_transports::{RpcError, TypedSubscriptionStream};
use jsonrpc_core::{futures_util::StreamExt, Value};
use std::{path::PathBuf, time::Duration};