Skip to content

Commit

Permalink
refactor: change to different cmd mode for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 9, 2021
1 parent 8bea135 commit e24ce2a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 31 deletions.
18 changes: 3 additions & 15 deletions src/helper/exec_wrapper/editor_exec.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
use crate::helper::exec_wrapper::exec_runner;
use std::error::Error;
use std::process::Command;

pub fn edit_file(editor: String, file: String) -> Result<(), Box<dyn Error>> {
if editor == "~" || editor == "" {
return Ok(());
}

let editor_cmd = format!("{:} {:?}", editor, file);

if cfg!(target_os = "windows") {
Command::new("cmd")
.args(["/C", editor_cmd.as_str()])
.spawn()?
.wait()?;
} else {
Command::new("sh")
.arg("-c")
.arg(editor_cmd)
.spawn()?
.wait()?;
};
let cmd = format!("{:} {:?}", editor, file);
exec_runner::cmd_runner(cmd)?;

Ok(())
}
19 changes: 19 additions & 0 deletions src/helper/exec_wrapper/exec_runner.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::error::Error;
use std::process::Command;

pub fn cmd_runner(editor_cmd: String) -> Result<(), Box<dyn Error>> {
if cfg!(target_os = "windows") {
Command::new("cmd")
.args(["/C", editor_cmd.as_str()])
.spawn()?
.wait()?;
} else {
Command::new("sh")
.arg("-c")
.arg(editor_cmd)
.spawn()?
.wait()?;
};

Ok(())
}
20 changes: 4 additions & 16 deletions src/helper/exec_wrapper/meili_exec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::helper::exec_wrapper::exec_runner;
use std::error::Error;
use std::process::Command;
use tracing::info;

pub fn feed_command(index_name: &String, search_url: &String) -> Result<(), Box<dyn Error>> {
Expand All @@ -12,11 +12,7 @@ pub fn feed_command(index_name: &String, search_url: &String) -> Result<(), Box<
);

info!("{:?}", cmd_line);
Command::new("/bin/sh")
.arg("-c")
.arg(cmd_line)
.spawn()?
.wait()?;
exec_runner::cmd_runner(cmd_line)?;

Ok(())
}
Expand All @@ -31,11 +27,7 @@ pub fn feed_settings(index_name: &String, search_url: &String) -> Result<(), Box
);

info!("{:?}", cmd_line);
Command::new("/bin/sh")
.arg("-c")
.arg(cmd_line)
.spawn()?
.wait()?;
exec_runner::cmd_runner(cmd_line)?;

Ok(())
}
Expand All @@ -54,11 +46,7 @@ pub fn feed_entry(
);

info!("{:?}", cmd_line);
Command::new("/bin/sh")
.arg("-c")
.arg(cmd_line)
.spawn()?
.wait()?;
exec_runner::cmd_runner(cmd_line)?;

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions src/helper/exec_wrapper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod editor_exec;
mod exec_runner;
pub(crate) mod meili_exec;

0 comments on commit e24ce2a

Please sign in to comment.