diff options
author | Aram Drevekenin <aram@poor.dev> | 2023-12-31 12:03:26 +0100 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2023-12-31 12:03:26 +0100 |
commit | cf4a8a63681f133fa6de109f2b46fa7468ca5778 (patch) | |
tree | cf34a5448c8cf8547169950b28ac97bf1f237c0c | |
parent | ac3189829da0a0792fbc12d3a2858fa3912ee086 (diff) |
refactor: adjust cli api
-rw-r--r-- | zellij-client/src/cli_client.rs | 23 | ||||
-rw-r--r-- | zellij-utils/src/cli.rs | 70 | ||||
-rw-r--r-- | zellij-utils/src/input/actions.rs | 31 |
3 files changed, 86 insertions, 38 deletions
diff --git a/zellij-client/src/cli_client.rs b/zellij-client/src/cli_client.rs index 423d38ba3..7e93cc66a 100644 --- a/zellij-client/src/cli_client.rs +++ b/zellij-client/src/cli_client.rs @@ -27,8 +27,8 @@ pub fn start_cli_client(mut os_input: Box<dyn ClientOsApi>, session_name: &str, for action in actions { match action { - Action::CliMessage { input_pipe_id, name, payload, plugin, args, configuration, launch_new, skip_cache, floating, in_place, cwd, pane_title } if payload.is_none() => { - pipe_client(&mut os_input, input_pipe_id, name, plugin, args, configuration, launch_new, skip_cache, floating, in_place, pane_id, cwd, pane_title); + Action::CliMessage { input_pipe_id, name, payload, plugin, args, configuration, launch_new, skip_cache, floating, in_place, cwd, pane_title } => { + pipe_client(&mut os_input, input_pipe_id, name, payload, plugin, args, configuration, launch_new, skip_cache, floating, in_place, pane_id, cwd, pane_title); }, action => { single_message_client(&mut os_input, action, pane_id); @@ -41,6 +41,7 @@ fn pipe_client( os_input: &mut Box<dyn ClientOsApi>, input_pipe_id: String, mut name: Option<String>, + payload: Option<String>, plugin: Option<String>, args: Option<BTreeMap<String, String>>, mut configuration: Option<BTreeMap<String, String>>, @@ -60,6 +61,24 @@ fn pipe_client( configuration.get_or_insert_with(BTreeMap::new).insert("_zellij_id".to_owned(), Uuid::new_v4().to_string()); } loop { + if payload.is_some() { + let msg = ClientToServerMsg::Action(Action::CliMessage{ + input_pipe_id: input_pipe_id.clone(), + name: name.clone(), + payload, + args: args.clone(), + plugin: plugin.clone(), + configuration: configuration.clone(), + floating, + in_place, + launch_new, + skip_cache, + cwd: cwd.clone(), + pane_title: pane_title.clone() + }, pane_id, None); + os_input.send_to_server(msg); + break; + } let mut buffer = String::new(); handle.read_line(&mut buffer).unwrap(); // TODO: no unwrap etc. if buffer.is_empty() { diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index 5a658539c..83d2e0f4e 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -549,29 +549,57 @@ pub enum CliAction { RenameSession { name: String, }, - Message { - #[clap(short, long, value_parser)] - name: Option<String>, // None would mean this is an anonymous message - payload: Option<String>, // TODO: Vec<u8>? - #[clap(short, long, value_parser)] + /// Send data to one or more plugins, launch them if they are not running. + #[clap(override_usage( +r#" +* Send data to a specific plugin: + +zellij action pipe --plugin file:/path/to/my/plugin.wasm --name my_pipe_name -- my-arbitrary-data + +* To all running plugins (that are listening): + +zellij action pipe --name my_pipe_name -- my-arbitrary-data + +* Pipe data into this command's STDIN and get output from the plugin on this command's STDOUT + +tail -f /tmp/my-live-logfile | zellij action pipe --name logs --plugin https://example.com/my-plugin.wasm | wc -l +"#))] + Pipe { + /// The name of the pipe + #[clap(short, long, value_parser, display_order(1))] + name: Option<String>, + /// The data to send down this pipe (if blank, will listen to STDIN) + payload: Option<String>, + + #[clap(short, long, value_parser, display_order(2))] + /// The args of the pipe args: Option<PluginUserConfiguration>, // TODO: we might want to not re-use // PluginUserConfiguration - #[clap(short, long, value_parser)] + /// The plugin url (eg. file:/tmp/my-plugin.wasm) to direct this pipe to, if not specified, + /// will be sent to all plugins, if specified and is not running, the plugin will be launched + #[clap(short, long, value_parser, display_order(3))] plugin: Option<String>, - #[clap(short, long, value_parser)] - configuration: Option<PluginUserConfiguration>, - #[clap(short, long, value_parser)] - launch_new: Option<bool>, - #[clap(short, long, value_parser)] - skip_cache: Option<bool>, - #[clap(short, long, value_parser)] - floating: Option<bool>, - #[clap(short, long, value_parser)] - in_place: Option<bool>, - /// Change the working directory of the new plugin - #[clap(long, value_parser)] - cwd: Option<PathBuf>, - #[clap(long, value_parser)] - pane_title: Option<String>, + /// The plugin configuration (note: the same plugin with different configuration is + /// considered a different plugin for the purposes of determining the pipe destination) + #[clap(short('c'), long, value_parser, display_order(4))] + plugin_configuration: Option<PluginUserConfiguration>, + /// Launch a new plugin even if one is already running + #[clap(short('l'), long, value_parser, takes_value(false), default_value("false"), display_order(5))] + force_launch_plugin: bool, + /// If launching a new plugin, skip cache and force-compile the plugin + #[clap(short('s'), long, value_parser, takes_value(false), default_value("false"), display_order(6))] + skip_plugin_cache: bool, + /// If launching a plugin, should it be floating or not, defaults to floating + #[clap(short('f'), long, value_parser, display_order(7))] + floating_plugin: Option<bool>, + /// If launching a plugin, launch it in-place (on top of the current pane) + #[clap(short('i'), long, value_parser, conflicts_with("floating-plugin"), display_order(8))] + in_place_plugin: Option<bool>, + /// If launching a plugin, specify its working directory + #[clap(short('w'), long, value_parser, display_order(9))] + plugin_cwd: Option<PathBuf>, + /// If launching a plugin, specify its pane title + #[clap(short('t'), long, value_parser, display_order(10))] + plugin_title: Option<String>, }, } diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index fc0db45de..6bd7e1a2e 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -258,6 +258,7 @@ pub enum Action { BreakPaneRight, BreakPaneLeft, RenameSession(String), + // TODO: rename to CLiPipe CliMessage { input_pipe_id: String, name: Option<String>, @@ -598,24 +599,24 @@ impl Action { )]) }, CliAction::RenameSession { name } => Ok(vec![Action::RenameSession(name)]), - CliAction::Message { + CliAction::Pipe { name, payload, args, plugin, - configuration, - launch_new, - skip_cache, - floating, - in_place, - cwd, - pane_title, + plugin_configuration, + force_launch_plugin, + skip_plugin_cache, + floating_plugin, + in_place_plugin, + plugin_cwd, + plugin_title, } => { let current_dir = get_current_dir(); - let cwd = cwd + let cwd = plugin_cwd .map(|cwd| current_dir.join(cwd)) .or_else(|| Some(current_dir)); - let skip_cache = skip_cache.unwrap_or(false); + let skip_cache = skip_plugin_cache; let input_pipe_id = Uuid::new_v4().to_string(); Ok(vec![Action::CliMessage{ input_pipe_id, @@ -623,13 +624,13 @@ impl Action { payload, args: args.map(|a| a.inner().clone()), // TODO: no clone somehow plugin, - configuration: configuration.map(|a| a.inner().clone()), // TODO: no clone + configuration: plugin_configuration.map(|a| a.inner().clone()), // TODO: no clone // somehow - launch_new: launch_new.unwrap_or(false), - floating, - in_place, + launch_new: force_launch_plugin, + floating: floating_plugin, + in_place: in_place_plugin, cwd, - pane_title, + pane_title: plugin_title, skip_cache, }]) }, |