Skip to content

Commit 91adffb

Browse files
committed
src/lib.rs: process:Command: let path
1 parent a13a032 commit 91adffb

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

src/lib.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,49 @@ pub use protocol::{Command, CommandTx, DiscoveryKey, Event, Key, Protocol};
144144
pub use util::discovery_key;
145145
use std::error::Error;
146146
use std::process;
147+
use std::process::Command;
147148
use std::fs;
148149

149150
#[derive(Debug)]
151+
use crate::process::Output;
152+
153+
static repo_root : String = std::env::args().nth(1).unwrap_or(".".to_string());
154+
const repo_path : Output =
155+
if cfg!(target_os = "windows") {
156+
Command::new("cmd")
157+
.args(["/C", "cd"])
158+
.output()
159+
.expect("failed to execute process")
160+
} else
161+
if cfg!(target_os = "macos"){
162+
Command::new("sh")
163+
.arg("-c")
164+
.arg("pwd")
165+
.output()
166+
.expect("failed to execute process")
167+
} else
168+
if cfg!(target_os = "linux"){
169+
Command::new("sh")
170+
.arg("-c")
171+
.arg("pwd")
172+
.output()
173+
.expect("failed to execute process")
174+
} else {
175+
Command::new("sh")
176+
.arg("-c")
177+
.arg("pwd")
178+
.output()
179+
.expect("failed to execute process")
180+
};
181+
182+
static path : String = String::from_utf8(repo_path.stdout)
183+
.map_err(|non_utf8| String::from_utf8_lossy(non_utf8.as_bytes()).into_owned())
184+
.unwrap();
185+
//println!("path={:?}", path);
186+
187+
188+
189+
150190
/// pub struct Config
151191
pub struct Config {
152192
pub query: String,

0 commit comments

Comments
 (0)