From 84ea28402d1883dc87a9fd88a1f334e7458edcf0 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Wed, 28 Jun 2023 01:05:44 -0500 Subject: [PATCH] Add support for distant spawn -c 'cmd str' --- CHANGELOG.md | 9 +++++++++ src/cli/commands/client.rs | 3 ++- src/options.rs | 21 +++++++++++++++------ 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4229f0a..59e4092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- CLI now supports `-c ` and `--cmd ` to use a given string as the + command as an alternative to `-- ` + +### Changed + +- Cli no longer uses `-c` as shorthand for specifying a config file + ## [0.20.0-alpha.10] ### Added diff --git a/src/cli/commands/client.rs b/src/cli/commands/client.rs index 6ba7b36..3ef4c01 100644 --- a/src/cli/commands/client.rs +++ b/src/cli/commands/client.rs @@ -364,6 +364,7 @@ async fn async_run(cmd: ClientSubcommand) -> CliResult { cache, connection, cmd, + cmd_str, current_dir, environment, lsp, @@ -388,7 +389,7 @@ async fn async_run(cmd: ClientSubcommand) -> CliResult { .with_context(|| format!("Failed to open channel to connection {connection_id}"))?; // Convert cmd into string - let cmd = cmd.join(" "); + let cmd = cmd_str.unwrap_or_else(|| cmd.join(" ")); if let Some(scheme) = lsp { debug!( diff --git a/src/options.rs b/src/options.rs index 7068b3a..6ffe38d 100644 --- a/src/options.rs +++ b/src/options.rs @@ -28,12 +28,8 @@ pub struct Options { #[clap(flatten)] pub logging: LoggingSettings, - #[cfg(feature = "tracing")] - #[clap(long, global = true)] - pub tracing: bool, - /// Configuration file to load instead of the default paths - #[clap(short = 'c', long = "config", global = true, value_parser)] + #[clap(long = "config", global = true, value_parser)] config_path: Option, #[clap(subcommand)] @@ -452,8 +448,17 @@ pub enum ClientSubcommand { #[clap(long, default_value_t)] environment: Map, + /// If present, commands are read from the provided string + #[clap(short = 'c', long = "cmd", conflicts_with = "CMD")] + cmd_str: Option, + /// Command to run - #[clap(name = "CMD", num_args = 1.., last = true)] + #[clap( + name = "CMD", + num_args = 1.., + last = true, + conflicts_with = "cmd_str" + )] cmd: Vec, }, @@ -1857,6 +1862,7 @@ mod tests { environment: map!(), lsp: Some(None), pty: true, + cmd_str: None, cmd: vec![String::from("cmd")], }), }; @@ -1895,6 +1901,7 @@ mod tests { environment: map!(), lsp: Some(None), pty: true, + cmd_str: None, cmd: vec![String::from("cmd")], }), } @@ -1920,6 +1927,7 @@ mod tests { environment: map!(), lsp: Some(None), pty: true, + cmd_str: None, cmd: vec![String::from("cmd")], }), }; @@ -1958,6 +1966,7 @@ mod tests { environment: map!(), lsp: Some(None), pty: true, + cmd_str: None, cmd: vec![String::from("cmd")], }), }