fix path
This commit is contained in:
14
src/main.rs
14
src/main.rs
@@ -94,7 +94,8 @@ fn run_setup() -> Result<()> {
|
|||||||
.expect("Cannot find config directory")
|
.expect("Cannot find config directory")
|
||||||
.join("ai.syui.log")
|
.join("ai.syui.log")
|
||||||
.join("config.json");
|
.join("config.json");
|
||||||
let aigpt_bin = std::env::current_exe().unwrap_or_else(|_| "aigpt".into());
|
let aigpt_bin = which_command("aigpt")
|
||||||
|
.unwrap_or_else(|| "aigpt".into());
|
||||||
|
|
||||||
// 1. ~/ai/
|
// 1. ~/ai/
|
||||||
std::fs::create_dir_all(&ai_dir)?;
|
std::fs::create_dir_all(&ai_dir)?;
|
||||||
@@ -156,12 +157,17 @@ fn run_setup() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_command_available(cmd: &str) -> bool {
|
fn which_command(cmd: &str) -> Option<std::path::PathBuf> {
|
||||||
Command::new("which")
|
Command::new("which")
|
||||||
.arg(cmd)
|
.arg(cmd)
|
||||||
.output()
|
.output()
|
||||||
.map(|o| o.status.success())
|
.ok()
|
||||||
.unwrap_or(false)
|
.filter(|o| o.status.success())
|
||||||
|
.map(|o| std::path::PathBuf::from(String::from_utf8_lossy(&o.stdout).trim()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_command_available(cmd: &str) -> bool {
|
||||||
|
which_command(cmd).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_status() {
|
fn print_status() {
|
||||||
|
|||||||
Reference in New Issue
Block a user