mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-04-30 05:39:45 +08:00
初步编写add逻辑;新增终端颜色库
This commit is contained in:
45
src/commands/add.rs
Normal file
45
src/commands/add.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use std::env;
|
||||
use std::path::{Path, PathBuf};
|
||||
use colored::Colorize;
|
||||
use crate::models::index::Index;
|
||||
use crate::utils::util::{check_repo_exist, get_working_dir, list_files};
|
||||
|
||||
pub fn add(files: Vec<String>, all: bool, mut update: bool) {
|
||||
check_repo_exist();
|
||||
let index = Index::new();
|
||||
let mut dot = files.contains(&".".to_string());
|
||||
|
||||
let mut files: Vec<PathBuf> = files.into_iter().map(PathBuf::from).collect();
|
||||
|
||||
if dot || all || update{
|
||||
if all { // all 优先级最高
|
||||
dot = false;
|
||||
update = false;
|
||||
} else if update {
|
||||
dot = false;
|
||||
}
|
||||
|
||||
let path = if all || update {
|
||||
println!("{}", "--all || --update 运行于工作区目录".bright_green());
|
||||
get_working_dir().unwrap()
|
||||
} else {
|
||||
println!("{}", "'.'代表了当前目录".bright_green());
|
||||
env::current_dir().unwrap()
|
||||
};
|
||||
println!("Working on [{}]\n", path.to_str().unwrap().bright_blue());
|
||||
files = list_files(&*path).unwrap();
|
||||
if update {
|
||||
files.retain(|file|{
|
||||
index.contains(file)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for file in files {
|
||||
add_a_file(file.as_path(), &index);
|
||||
}
|
||||
}
|
||||
|
||||
fn add_a_file(file: &Path, index: &Index) {
|
||||
println!("add a file: {:?}", file);
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
use std::{env, fs, io};
|
||||
use crate::utils::util::ROOT_DIR;
|
||||
|
||||
/**
|
||||
初始化mit仓库 创建.mit/objects .mit/refs/heads .mit/HEAD
|
||||
@@ -7,7 +8,7 @@ use std::{env, fs, io};
|
||||
*/
|
||||
pub fn init() -> io::Result<()> {
|
||||
let dir = env::current_dir()?;
|
||||
let mit_dir = dir.join(".mit");
|
||||
let mit_dir = dir.join(ROOT_DIR);
|
||||
if mit_dir.exists() {
|
||||
println!("!Already a mit repo - [{}]", dir.display());
|
||||
return Ok(());
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod init;
|
||||
pub mod init;
|
||||
pub mod add;
|
||||
Reference in New Issue
Block a user