now exporting path variable at the start of the application

This commit is contained in:
2023-03-06 21:46:12 +01:00
parent 571f93ed62
commit b9f4f86758
3 changed files with 20 additions and 9 deletions

View File

@@ -2,6 +2,8 @@ use std::{collections::HashMap, process, io::ErrorKind};
use colored::Colorize;
use crate::app::fs_util;
use super::traits::Command;
pub struct Health;
@@ -71,7 +73,9 @@ impl Health {
}
fn check_command(command: &str) -> bool {
return match process::Command::new(command).output() {
return match process::Command::new(command)
// .env("PATH", fs_util::docki_path_env())
.output() {
Ok(_) => true,
Err(e) => ErrorKind::NotFound != e.kind()
}

View File

@@ -1,4 +1,4 @@
use std::{fs, path::Path, env};
use std::{env, fs, path::Path};
struct RecursivePathFetch {
paths: Vec<String>,
@@ -53,8 +53,7 @@ impl RecursivePathFetch {
}
pub fn fetch_paths_recursive(path: &str) -> Result<Vec<String>, String> {
let mut path_fetch =
RecursivePathFetch::new_with_extension_filter(path.to_string());
let mut path_fetch = RecursivePathFetch::new_with_extension_filter(path.to_string());
return path_fetch.fetch();
}
@@ -73,11 +72,13 @@ pub fn directory_exists(path: &String) -> bool {
Path::new(path).is_dir()
}
pub fn expand_path(path: String) -> String {
let home_dir = env::var("HOME")
.expect("could not find home dir");
return path.replace("~", &home_dir)
let home_dir = env::var("HOME").expect("could not find home dir");
return path.replace("~", &home_dir);
}
pub fn docki_path_env() -> String {
let current = env::var("PATH").unwrap_or("".to_string());
return expand_path(format!("{}:~/.docki/", current));
}

View File

@@ -3,6 +3,7 @@ pub mod builder;
pub mod fs_util;
use std::collections::HashMap;
use std::env;
use commands::traits::Command;
use commands::CommandRegistry;
@@ -19,6 +20,7 @@ impl App {
}
pub fn start(self, args: Vec<String>) {
Self::preapare_env_path();
let command_args = &args[1..];
let mut path = String::from("");
let mut argument_map = HashMap::new();
@@ -45,6 +47,10 @@ impl App {
self.execute_path(&path, &argument_map);
}
fn preapare_env_path() {
env::set_var("PATH", fs_util::docki_path_env());
}
fn execute_path(self, path: &String, args: &HashMap<String, String>) {
let command = self.command_regisrty.command_by(path);