Changed the way we deal with the folder location for tasks
This commit is contained in:
parent
ac631f9b67
commit
b4039f444f
|
@ -32,7 +32,7 @@ impl Entry {
|
|||
}
|
||||
|
||||
/// Load single entry from folder
|
||||
pub fn entry(basedir: &str, filter: impl Fn(&Path) -> bool, name: &str) -> Option<Entry> {
|
||||
pub fn entry(basedir: &Path, filter: impl Fn(&Path) -> bool, name: &str) -> Option<Entry> {
|
||||
let basepath = PathBuf::from(&basedir);
|
||||
let path = basepath.clone().join(name);
|
||||
|
||||
|
@ -48,7 +48,7 @@ pub fn entry(basedir: &str, filter: impl Fn(&Path) -> bool, name: &str) -> Optio
|
|||
}
|
||||
|
||||
/// Loads entire database from folder
|
||||
pub fn from(path_name: &str, filter: impl Fn(&Path) -> bool) -> Result<Vec<Entry>, std::io::Error> {
|
||||
pub fn from(path_name: &Path, filter: impl Fn(&Path) -> bool) -> Result<Vec<Entry>, std::io::Error> {
|
||||
let path = PathBuf::from(&path_name);
|
||||
|
||||
let mut entries = Vec::new();
|
||||
|
|
19
src/dvcs.rs
19
src/dvcs.rs
|
@ -36,4 +36,23 @@ impl Backend {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&self) -> bool {
|
||||
match self {
|
||||
Backend::Git => {
|
||||
let status = Command::new("git")
|
||||
.arg("pull")
|
||||
.status()
|
||||
.expect("Failed to pull on git repo.");
|
||||
status.success()
|
||||
},
|
||||
Backend::Mercurial => {
|
||||
unreachable!("Unimplemented");
|
||||
},
|
||||
Backend::Unknown(name) => {
|
||||
eprintln!("Unknown DVCS: {}", name);
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
34
src/main.rs
34
src/main.rs
|
@ -13,16 +13,32 @@ mod task;
|
|||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
|
||||
let home_dir = env::var("HOME").expect("$HOME not defined. WTF?");
|
||||
let base_dir = format!("{}/.git-build", home_dir);
|
||||
let default_folder;
|
||||
|
||||
// Check if we defined a given folder in which to find the tasks
|
||||
let base_dir = match env::var_os("GITBUILDDIR") {
|
||||
Some(val) => {
|
||||
default_folder = false;
|
||||
Path::new(&val)
|
||||
},
|
||||
None => {
|
||||
default_folder = true;
|
||||
let home_dir = env::var("HOME").expect("$HOME not defined. WTF?");
|
||||
Path::new(&format!("{}/.git-build", home_dir))
|
||||
}
|
||||
};
|
||||
|
||||
// If we're not using a GITBUILDDIR folder,
|
||||
// We're gonna check if they already is a .git-build folder, and create one otherwise.
|
||||
if !Path::new(&base_dir).exists() {
|
||||
log::info("create_git_build_folder", Some(&HashMap::new()));
|
||||
|
||||
DirBuilder::new()
|
||||
if !base_dir.exists() {
|
||||
if default_folder == false {
|
||||
// log::error("no_folder", HashMap::new().insert("$i18n_folder", &base_dir.to_str().unwrap() ) );
|
||||
} else {
|
||||
log::info("create_git_build_folder", Some(&HashMap::new()));
|
||||
DirBuilder::new()
|
||||
.recursive(true)
|
||||
.create(&base_dir).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
let cmd = cli::Cli::from_args();
|
||||
|
@ -52,7 +68,11 @@ fn main() -> Result<(), std::io::Error> {
|
|||
// Otherwise, it's a sourceless task
|
||||
continue
|
||||
}
|
||||
// So the cloned repo is here maybe update?
|
||||
// The repo has been cloned already, we update it.
|
||||
task.dvcs.update();
|
||||
|
||||
|
||||
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::path::PathBuf;
|
||||
use std::path::{PathBuf, Path};
|
||||
use std::ffi::OsString;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
@ -57,7 +57,7 @@ pub fn from_entries(db: Vec<Entry>) -> HashMap<String, Task> {
|
|||
|
||||
/// Returns a hashmap of tasks, or std::io::Error
|
||||
/// Reads all entries in a directory
|
||||
pub fn from_dir(base_dir: &str) -> Result<HashMap<String, Task>, std::io::Error> {
|
||||
pub fn from_dir(base_dir: &Path) -> Result<HashMap<String, Task>, std::io::Error> {
|
||||
Ok(from_entries(
|
||||
db::from(base_dir, is_executable)?
|
||||
))
|
||||
|
@ -66,7 +66,7 @@ pub fn from_dir(base_dir: &str) -> Result<HashMap<String, Task>, std::io::Error>
|
|||
/// Returns a hashmap of tasks, or std::io::Error
|
||||
/// Reads entries in a given list from a directory, fails if a requested entry doesn't exist
|
||||
/// (does not load the whole folder)
|
||||
pub fn from_dir_and_list(basedir: &str, list: Vec<String>) -> Result<HashMap<String, Task>, db::Error> {
|
||||
pub fn from_dir_and_list(basedir: &Path, list: Vec<String>) -> Result<HashMap<String, Task>, db::Error> {
|
||||
let mut entries: HashMap<String, Task> = HashMap::new();
|
||||
for item in list {
|
||||
if let Some(entry) = db::entry(&basedir, is_executable, &item) {
|
||||
|
|
Loading…
Reference in New Issue