From 4de689caa7a7d27a451d24f33393e254b398fdd3 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Fri, 26 Apr 2024 09:46:51 +0200 Subject: [PATCH] allow passing parameters to execute_dev_command commands --- libs/Cargo.lock | 140 +++++++++++++++-- libs/sdk-core/Cargo.toml | 2 + libs/sdk-core/src/greenlight/error.rs | 6 + libs/sdk-core/src/greenlight/node_api.rs | 19 ++- tools/sdk-cli/Cargo.lock | 184 ++++++++++++++++++++--- tools/sdk-cli/Cargo.toml | 3 +- tools/sdk-cli/src/command_handlers.rs | 5 +- tools/sdk-cli/src/commands.rs | 5 +- tools/sdk-cli/src/main.rs | 5 +- 9 files changed, 330 insertions(+), 39 deletions(-) diff --git a/libs/Cargo.lock b/libs/Cargo.lock index ea522fb00..44e16d711 100644 --- a/libs/Cargo.lock +++ b/libs/Cargo.lock @@ -112,6 +112,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "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]] name = "anyhow" version = "1.0.79" @@ -520,6 +568,7 @@ dependencies = [ "bip21", "cbc", "chrono", + "clap 4.5.4", "const_format", "ecies", "env_logger 0.10.1", @@ -544,6 +593,7 @@ dependencies = [ "serde", "serde_json", "serde_with", + "shlex", "strum", "strum_macros", "tempfile", @@ -721,28 +771,62 @@ checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", "bitflags 1.3.2", - "clap_derive", - "clap_lex", + "clap_derive 3.2.25", + "clap_lex 0.2.4", "indexmap 1.9.3", "once_cell", - "strsim", + "strsim 0.10.0", "termcolor", "textwrap", ] +[[package]] +name = "clap" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" +dependencies = [ + "clap_builder", + "clap_derive 4.5.4", +] + +[[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 0.7.0", + "strsim 0.11.1", +] + [[package]] name = "clap_derive" version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro-error", "proc-macro2", "quote", "syn 1.0.109", ] +[[package]] +name = "clap_derive" +version = "4.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.48", +] + [[package]] name = "clap_lex" version = "0.2.4" @@ -752,6 +836,12 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "clap_lex" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" + [[package]] name = "cln-grpc" version = "0.1.7" @@ -767,6 +857,12 @@ dependencies = [ "tonic-build", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "colored" version = "2.0.4" @@ -879,7 +975,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 2.0.48", ] @@ -1411,6 +1507,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -2322,7 +2424,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", - "heck", + "heck 0.4.1", "itertools", "lazy_static", "log", @@ -2908,6 +3010,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2988,6 +3096,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.25.0" @@ -3000,7 +3114,7 @@ version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -3475,7 +3589,7 @@ checksum = "f71cc01459bc34cfe43fabf32b39f1228709bc6db1b3a664a92940af3d062376" dependencies = [ "anyhow", "camino", - "clap", + "clap 3.2.25", "uniffi_bindgen", "uniffi_core", "uniffi_macros", @@ -3489,7 +3603,7 @@ dependencies = [ "anyhow", "askama", "camino", - "heck", + "heck 0.4.1", "include_dir", "paste", "serde", @@ -3510,7 +3624,7 @@ dependencies = [ "fs-err", "glob", "goblin", - "heck", + "heck 0.4.1", "once_cell", "paste", "serde", @@ -3636,6 +3750,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.6.1" diff --git a/libs/sdk-core/Cargo.toml b/libs/sdk-core/Cargo.toml index 067a73cef..9c3561b65 100644 --- a/libs/sdk-core/Cargo.toml +++ b/libs/sdk-core/Cargo.toml @@ -62,6 +62,8 @@ miniz_oxide = "0.7.1" tokio-stream = "0.1.14" serde_with = "3.3.0" regex = "1.8.1" +clap = { version = "4.5.4", features = ["derive"] } +shlex = "1.3.0" [dev-dependencies] mockito = "1" diff --git a/libs/sdk-core/src/greenlight/error.rs b/libs/sdk-core/src/greenlight/error.rs index d54fb13df..bf4fe6ec4 100644 --- a/libs/sdk-core/src/greenlight/error.rs +++ b/libs/sdk-core/src/greenlight/error.rs @@ -207,6 +207,12 @@ impl From for NodeError { } } +impl From for NodeError { + fn from(err: clap::Error) -> Self { + Self::Generic(anyhow::Error::new(err)) + } +} + #[allow(clippy::invalid_regex)] pub(crate) fn parse_cln_error(status: tonic::Status) -> Result { let re: Regex = Regex::new(r"Some\((?-?\d+)\)")?; diff --git a/libs/sdk-core/src/greenlight/node_api.rs b/libs/sdk-core/src/greenlight/node_api.rs index b5f5f848c..7d8c97e5b 100644 --- a/libs/sdk-core/src/greenlight/node_api.rs +++ b/libs/sdk-core/src/greenlight/node_api.rs @@ -6,6 +6,7 @@ use std::sync::Arc; use std::time::{Duration, SystemTime, UNIX_EPOCH}; use anyhow::{anyhow, Result}; +use clap::Parser; use ecies::symmetric::{sym_decrypt, sym_encrypt}; use futures::Stream; use gl_client::node::ClnClient; @@ -1427,9 +1428,10 @@ impl NodeAPI for Greenlight { } async fn execute_command(&self, command: String) -> NodeResult { - let node_cmd = - NodeCommand::from_str(&command).map_err(|_| anyhow!("Command not found: {command}"))?; - match node_cmd { + let mut args = shlex::split(&command).ok_or(anyhow!("Command not found: {command}"))?; + args.insert(0, String::from(" ")); + let command = NodeCommand::try_parse_from(args)?; + match command { NodeCommand::ListPeers => { let resp = self .get_node_client() @@ -1666,37 +1668,45 @@ impl NodeAPI for Greenlight { } } -#[derive(Clone, PartialEq, Eq, Debug, EnumString, Display, Deserialize, Serialize)] +#[derive(Parser, Clone, PartialEq, Eq, Debug, EnumString, Display, Deserialize, Serialize)] enum NodeCommand { /// Generates diagnostic data report. + #[command(name = "generatediagnosticdata")] #[strum(serialize = "generatediagnosticdata")] GenerateDiagnosticData, /// Closes all channels of all peers. + #[command(name = "closeallchannels")] #[strum(serialize = "closeallchannels")] CloseAllChannels, /// See + #[command(name = "getinfo")] #[strum(serialize = "getinfo")] GetInfo, /// See + #[command(name = "listfunds")] #[strum(serialize = "listfunds")] ListFunds, /// See + #[command(name = "listinvoices")] #[strum(serialize = "listinvoices")] ListInvoices, /// See + #[command(name = "listpayments")] #[strum(serialize = "listpayments")] ListPayments, /// See + #[command(name = "listpeers")] #[strum(serialize = "listpeers")] ListPeers, /// See + #[command(name = "listpeerchannels")] #[strum(serialize = "listpeerchannels")] ListPeerChannels, @@ -1705,6 +1715,7 @@ enum NodeCommand { /// Note that this command will return an error, as the node is stopped before it can reply. /// /// See + #[command(name = "stop")] #[strum(serialize = "stop")] Stop, } diff --git a/tools/sdk-cli/Cargo.lock b/tools/sdk-cli/Cargo.lock index 94f3b4c5d..36b3b7182 100644 --- a/tools/sdk-cli/Cargo.lock +++ b/tools/sdk-cli/Cargo.lock @@ -105,6 +105,54 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.6.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +dependencies = [ + "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]] name = "anyhow" version = "1.0.79" @@ -452,6 +500,7 @@ dependencies = [ "rustyline", "serde", "serde_json", + "shlex", "tiny-bip39", "tokio", ] @@ -466,6 +515,7 @@ dependencies = [ "bip21", "cbc", "chrono", + "clap", "const_format", "ecies", "env_logger 0.10.0", @@ -489,6 +539,7 @@ dependencies = [ "serde", "serde_json", "serde_with", + "shlex", "strum", "strum_macros", "tempfile", @@ -604,35 +655,33 @@ dependencies = [ [[package]] name = "clap" -version = "4.1.14" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "906f7fe1da4185b7a282b2bc90172a496f9def1aca4545fe7526810741591e14" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ "clap_builder", "clap_derive", - "once_cell", ] [[package]] name = "clap_builder" -version = "4.1.14" +version = "4.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "351f9ad9688141ed83dfd8f5fb998a06225ef444b48ff4dc43de6d409b7fd10b" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" dependencies = [ - "bitflags 1.3.2", + "anstream", + "anstyle", "clap_lex", - "is-terminal", - "strsim", - "termcolor", + "strsim 0.11.1", ] [[package]] name = "clap_derive" -version = "4.1.14" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81d7dc0031c3a59a04fc2ba395c8e2dd463cba1859275f065d225f6122221b45" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck", + "heck 0.5.0", "proc-macro2", "quote", "syn 2.0.48", @@ -640,9 +689,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.4.1" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "clipboard-win" @@ -670,6 +719,12 @@ dependencies = [ "tonic-build", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "console_error_panic_hook" version = "0.1.7" @@ -771,7 +826,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 2.0.48", ] @@ -1313,6 +1368,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -2178,7 +2239,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270" dependencies = [ "bytes", - "heck", + "heck 0.4.1", "itertools", "lazy_static", "log", @@ -2782,6 +2843,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2834,6 +2901,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum" version = "0.25.0" @@ -2842,11 +2915,11 @@ checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125" [[package]] name = "strum_macros" -version = "0.25.2" +version = "0.25.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad8d03b598d3d0fff69bf533ee3ef19b8eeb342729596df84bcc7e1f96ec4059" +checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0" dependencies = [ - "heck", + "heck 0.4.1", "proc-macro2", "quote", "rustversion", @@ -3618,6 +3691,15 @@ dependencies = [ "windows-targets 0.48.0", ] +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets 0.52.5", +] + [[package]] name = "windows-targets" version = "0.42.2" @@ -3648,6 +3730,22 @@ dependencies = [ "windows_x86_64_msvc 0.48.0", ] +[[package]] +name = "windows-targets" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +dependencies = [ + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -3660,6 +3758,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" @@ -3672,6 +3776,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" + [[package]] name = "windows_i686_gnu" version = "0.42.2" @@ -3684,6 +3794,18 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +[[package]] +name = "windows_i686_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" + [[package]] name = "windows_i686_msvc" version = "0.42.2" @@ -3696,6 +3818,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +[[package]] +name = "windows_i686_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" @@ -3708,6 +3836,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" @@ -3720,6 +3854,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" @@ -3732,6 +3872,12 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" + [[package]] name = "winreg" version = "0.50.0" diff --git a/tools/sdk-cli/Cargo.toml b/tools/sdk-cli/Cargo.toml index a0f6605fa..7a46e5560 100644 --- a/tools/sdk-cli/Cargo.toml +++ b/tools/sdk-cli/Cargo.toml @@ -16,4 +16,5 @@ serde_json = "1.0" tiny-bip39 = "1" tokio = { version = "1", features = ["rt-multi-thread"] } serde = { version = "1.0", features = ["derive"] } -clap = { version = "4", features = ["derive"] } \ No newline at end of file +clap = { version = "4", features = ["derive"] } +shlex = "1.3.0" diff --git a/tools/sdk-cli/src/command_handlers.rs b/tools/sdk-cli/src/command_handlers.rs index f81c24a9f..33f036030 100644 --- a/tools/sdk-cli/src/command_handlers.rs +++ b/tools/sdk-cli/src/command_handlers.rs @@ -562,8 +562,9 @@ pub(crate) async fn handle_command( .await?; Ok("Report sent".into()) } - Commands::ExecuteDevCommand { command } => { - serde_json::to_string_pretty(&sdk()?.execute_dev_command(command).await?) + Commands::ExecuteDevCommand { args } => { + let joined = shlex::try_join(args.iter().map(|s| s.as_ref()))?; + serde_json::to_string_pretty(&sdk()?.execute_dev_command(joined).await?) .map_err(|e| e.into()) } Commands::GenerateDiagnosticData {} => Ok(sdk()?.generate_diagnostic_data().await?), diff --git a/tools/sdk-cli/src/commands.rs b/tools/sdk-cli/src/commands.rs index 5e5b7a947..279d84c78 100644 --- a/tools/sdk-cli/src/commands.rs +++ b/tools/sdk-cli/src/commands.rs @@ -317,7 +317,10 @@ pub(crate) enum Commands { FetchFiatRates {}, /// [dev] Execute a low level node command (used for debugging) - ExecuteDevCommand { command: String }, + ExecuteDevCommand { + #[arg(trailing_var_arg = true, allow_hyphen_values = true, hide = true)] + args: Vec, + }, /// [dev] Generates and retrieves a diagnostic data report from the sdk services (used for debugging) GenerateDiagnosticData {}, diff --git a/tools/sdk-cli/src/main.rs b/tools/sdk-cli/src/main.rs index 78c50a223..c3f5eca42 100644 --- a/tools/sdk-cli/src/main.rs +++ b/tools/sdk-cli/src/main.rs @@ -45,8 +45,9 @@ async fn main() -> Result<()> { match readline { Ok(line) => { rl.add_history_entry(line.as_str())?; - let mut vec: Vec<&str> = line.as_str().split_whitespace().collect(); - vec.insert(0, " "); + let mut vec: Vec = + shlex::split(&line).ok_or(anyhow!("Could not parse command"))?; + vec.insert(0, String::from(" ")); let cli_res = Commands::try_parse_from(vec); if cli_res.is_err() { println!("{}", cli_res.unwrap_err());