zellij_utils/plugin_api/
command.rs

1pub use super::generated_api::api::command::Command as ProtobufCommand;
2use crate::data::CommandToRun;
3
4use std::convert::TryFrom;
5use std::path::PathBuf;
6
7impl TryFrom<ProtobufCommand> for CommandToRun {
8    type Error = &'static str;
9    fn try_from(protobuf_command: ProtobufCommand) -> Result<Self, &'static str> {
10        let path = PathBuf::from(protobuf_command.path);
11        let args = protobuf_command.args;
12        let cwd = protobuf_command.cwd.map(|c| PathBuf::from(c));
13        Ok(CommandToRun { path, args, cwd })
14    }
15}
16
17impl TryFrom<CommandToRun> for ProtobufCommand {
18    type Error = &'static str;
19    fn try_from(command_to_run: CommandToRun) -> Result<Self, &'static str> {
20        Ok(ProtobufCommand {
21            path: command_to_run.path.display().to_string(),
22            args: command_to_run.args,
23            cwd: command_to_run.cwd.map(|c| c.display().to_string()),
24        })
25    }
26}