Compare commits

...

2 Commits

Author SHA1 Message Date
14f8209be3 feat: add script config struct 2020-07-26 11:07:47 +08:00
db51056cd1 feat: add get_git_base_dir 2020-07-26 11:07:30 +08:00
2 changed files with 41 additions and 0 deletions

View File

@@ -1,5 +1,24 @@
use std::path::PathBuf;
use std::process::Command; use std::process::Command;
pub fn get_git_base_path() -> Option<PathBuf> {
match PathBuf::from(".").canonicalize() {
Err(e) => {
warn!("Get current path failed: {}", e);
None
},
Ok(mut path) => loop {
if path.join(".git").is_dir() {
debug!("Found git base dir: {:?}", path)
return Some(path);
}
if !path.pop() {
return None;
}
}
}
}
pub fn check_git_status() -> bool { pub fn check_git_status() -> bool {
trace!("Run: git fetch --dry-run"); trace!("Run: git fetch --dry-run");
match Command::new("git").env("LANG", "en_US").args(&["fetch", "--dry-run"]).output() { match Command::new("git").env("LANG", "en_US").args(&["fetch", "--dry-run"]).output() {

View File

@@ -1,5 +1,27 @@
use std::fs; use std::fs;
use std::path::PathBuf; use std::path::PathBuf;
use serde::{ Deserialize, Serialize };
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScriptDescription {
pub name: String,
pub version: String,
pub hash: String,
pub repo: String,
#[serde(rename = "gitHash")]
pub git_hash: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScriptConfig {
pub repo: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ScriptLocalConfig {
#[serde(rename = "indexPath")]
pub index_path: String,
}
pub fn _get_script_base_path(base: &PathBuf, file_name: &str) -> PathBuf { pub fn _get_script_base_path(base: &PathBuf, file_name: &str) -> PathBuf {
let mut fn_chars = file_name.chars().take_while(|c| *c != '.'); let mut fn_chars = file_name.chars().take_while(|c| *c != '.');