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 colored::Colorize;
use crate::app::fs_util;
use super::traits::Command; use super::traits::Command;
pub struct Health; pub struct Health;
@@ -71,7 +73,9 @@ impl Health {
} }
fn check_command(command: &str) -> bool { 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, Ok(_) => true,
Err(e) => ErrorKind::NotFound != e.kind() 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 { struct RecursivePathFetch {
paths: Vec<String>, paths: Vec<String>,
@@ -53,8 +53,7 @@ impl RecursivePathFetch {
} }
pub fn fetch_paths_recursive(path: &str) -> Result<Vec<String>, String> { pub fn fetch_paths_recursive(path: &str) -> Result<Vec<String>, String> {
let mut path_fetch = let mut path_fetch = RecursivePathFetch::new_with_extension_filter(path.to_string());
RecursivePathFetch::new_with_extension_filter(path.to_string());
return path_fetch.fetch(); return path_fetch.fetch();
} }
@@ -73,11 +72,13 @@ pub fn directory_exists(path: &String) -> bool {
Path::new(path).is_dir() Path::new(path).is_dir()
} }
pub fn expand_path(path: String) -> String { pub fn expand_path(path: String) -> String {
let home_dir = env::var("HOME") let home_dir = env::var("HOME").expect("could not find home dir");
.expect("could not find home dir");
return path.replace("~", &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; pub mod fs_util;
use std::collections::HashMap; use std::collections::HashMap;
use std::env;
use commands::traits::Command; use commands::traits::Command;
use commands::CommandRegistry; use commands::CommandRegistry;
@@ -19,6 +20,7 @@ impl App {
} }
pub fn start(self, args: Vec<String>) { pub fn start(self, args: Vec<String>) {
Self::preapare_env_path();
let command_args = &args[1..]; let command_args = &args[1..];
let mut path = String::from(""); let mut path = String::from("");
let mut argument_map = HashMap::new(); let mut argument_map = HashMap::new();
@@ -45,6 +47,10 @@ impl App {
self.execute_path(&path, &argument_map); 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>) { fn execute_path(self, path: &String, args: &HashMap<String, String>) {
let command = self.command_regisrty.command_by(path); let command = self.command_regisrty.command_by(path);