summaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/cli.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2024-01-17 12:10:49 +0100
committerGitHub <noreply@github.com>2024-01-17 12:10:49 +0100
commitd780bd91052d8282ba5a7f06c6fb7faa7ca7cc18 (patch)
treeca08219a38b9e6a3b1c027682359074c86e0dbb5 /zellij-utils/src/cli.rs
parentf6d57295a02393e26c74afb007bf673bcbb454e8 (diff)
feat(plugins): introduce 'pipes', allowing users to pipe data to and control plugins from the command line (#3066)
* prototype - working with message from the cli * prototype - pipe from the CLI to plugins * prototype - pipe from the CLI to plugins and back again * prototype - working with better cli interface * prototype - working after removing unused stuff * prototype - working with launching plugin if it is not launched, also fixed event ordering * refactor: change message to cli-message * prototype - allow plugins to send messages to each other * fix: allow cli messages to send plugin parameters (and implement backpressure) * fix: use input_pipe_id to identify cli pipes instead of their message name * fix: come cleanups and add skip_cache parameter * fix: pipe/client-server communication robustness * fix: leaking messages between plugins while loading * feat: allow plugins to specify how a new plugin instance is launched when sending messages * fix: add permissions * refactor: adjust cli api * fix: improve cli plugin loading error messages * docs: cli pipe * fix: take plugin configuration into account when messaging between plugins * refactor: pipe message protobuf interface * refactor: update(event) -> pipe * refactor - rename CliMessage to CliPipe * fix: add is_private to pipes and change some naming * refactor - cli client * refactor: various cleanups * style(fmt): rustfmt * fix(pipes): backpressure across multiple plugins * style: some cleanups * style(fmt): rustfmt * style: fix merge conflict mistake * style(wording): clarify pipe permission
Diffstat (limited to 'zellij-utils/src/cli.rs')
-rw-r--r--zellij-utils/src/cli.rs112
1 files changed, 112 insertions, 0 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs
index 97a0cd778..bf8f8880d 100644
--- a/zellij-utils/src/cli.rs
+++ b/zellij-utils/src/cli.rs
@@ -289,6 +289,43 @@ pub enum Sessions {
ConvertTheme {
old_theme_file: PathBuf,
},
+ /// Send data to one or more plugins, launch them if they are not running.
+ #[clap(override_usage(
+r#"
+zellij pipe [OPTIONS] [--] <PAYLOAD>
+
+* Send data to a specific plugin:
+
+zellij pipe --plugin file:/path/to/my/plugin.wasm --name my_pipe_name -- my_arbitrary_data
+
+* To all running plugins (that are listening):
+
+zellij 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 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
+ /// 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>,
+ /// 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>,
+ },
}
#[derive(Debug, Subcommand, Clone, Serialize, Deserialize)]
@@ -549,4 +586,79 @@ pub enum CliAction {
RenameSession {
name: String,
},
+ /// Send data to one or more plugins, launch them if they are not running.
+ #[clap(override_usage(
+r#"
+zellij action pipe [OPTIONS] [--] <PAYLOAD>
+
+* 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
+ /// 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>,
+ /// 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>,
+ },
}