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