start add command
This commit is contained in:
parent
04bef223a3
commit
f1724d23f5
@ -1,2 +1,3 @@
|
|||||||
pub mod init;
|
pub mod init;
|
||||||
pub mod status;
|
pub mod status;
|
||||||
|
pub mod add;
|
||||||
|
18
src/commands/add.rs
Normal file
18
src/commands/add.rs
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
use clap::Values;
|
||||||
|
use crate::utils;
|
||||||
|
|
||||||
|
pub fn add(files: Values<'_>) {
|
||||||
|
let root = match utils::path::nextsync_root() {
|
||||||
|
Some(path) => path,
|
||||||
|
None => {
|
||||||
|
eprintln!("fatal: not a nextsync repository (or any of the parent directories): .nextsync");
|
||||||
|
std::process::exit(1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
dbg!(root.clone());
|
||||||
|
let file_vec: Vec<&str> = files.collect();
|
||||||
|
for file in file_vec {
|
||||||
|
println!("{}", file);
|
||||||
|
}
|
||||||
|
}
|
@ -18,6 +18,13 @@ pub fn init() {
|
|||||||
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path.pop();
|
||||||
|
path.push("index");
|
||||||
|
match File::create(path.clone()) {
|
||||||
|
Ok(_) => println!("File successfuly created"),
|
||||||
|
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
||||||
|
}
|
||||||
|
|
||||||
path.pop();
|
path.pop();
|
||||||
path.pop();
|
path.pop();
|
||||||
path.push(".nextsyncignore");
|
path.push(".nextsyncignore");
|
||||||
@ -26,5 +33,4 @@ pub fn init() {
|
|||||||
Ok(_) => println!("File successfuly created"),
|
Ok(_) => println!("File successfuly created"),
|
||||||
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
Err(_) => println!("Error: cannot create .nextsyncignore"),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,8 @@ use std::collections::HashSet;
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
// todo: relative path, filename
|
// todo: relative path, filename, get modified
|
||||||
pub fn status() {
|
pub fn status() {
|
||||||
let mut new_files: Vec<PathBuf> = Vec::new();
|
|
||||||
let mut hashes = HashSet::new();
|
let mut hashes = HashSet::new();
|
||||||
let mut objects: Vec<String> = vec![];
|
let mut objects: Vec<String> = vec![];
|
||||||
|
|
||||||
@ -102,7 +101,7 @@ fn read_folder(path: PathBuf) -> io::Result<Vec<PathBuf>> {
|
|||||||
let mut entries = fs::read_dir(path)?
|
let mut entries = fs::read_dir(path)?
|
||||||
.map(|res| res.map(|e| e.path()))
|
.map(|res| res.map(|e| e.path()))
|
||||||
.collect::<Result<Vec<_>, io::Error>>()?;
|
.collect::<Result<Vec<_>, io::Error>>()?;
|
||||||
|
|
||||||
entries.sort();
|
entries.sort();
|
||||||
Ok(entries)
|
Ok(entries)
|
||||||
}
|
}
|
||||||
|
19
src/main.rs
19
src/main.rs
@ -6,8 +6,9 @@
|
|||||||
//use std::env;
|
//use std::env;
|
||||||
//use dotenv::dotenv;
|
//use dotenv::dotenv;
|
||||||
|
|
||||||
use clap::{App, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
mod commands;
|
mod commands;
|
||||||
|
mod utils;
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = App::new("NextSync")
|
let matches = App::new("NextSync")
|
||||||
.version("1.0")
|
.version("1.0")
|
||||||
@ -15,14 +16,30 @@ fn main() {
|
|||||||
.about("")
|
.about("")
|
||||||
.subcommand(SubCommand::with_name("init"))
|
.subcommand(SubCommand::with_name("init"))
|
||||||
.subcommand(SubCommand::with_name("status"))
|
.subcommand(SubCommand::with_name("status"))
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("add")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("files")
|
||||||
|
.required(true)
|
||||||
|
.multiple(true)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("FILE")
|
||||||
|
.help("Files to add"),
|
||||||
|
)
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
if let Some(_) = matches.subcommand_matches("init") {
|
if let Some(_) = matches.subcommand_matches("init") {
|
||||||
commands::init::init();
|
commands::init::init();
|
||||||
} else if let Some(_) = matches.subcommand_matches("status") {
|
} else if let Some(_) = matches.subcommand_matches("status") {
|
||||||
commands::status::status();
|
commands::status::status();
|
||||||
|
} else if let Some(matches) = matches.subcommand_matches("add") {
|
||||||
|
if let Some(files) = matches.values_of("files") {
|
||||||
|
commands::add::add(files);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//tokio::runtime::Runtime::new().unwrap().block_on(async {
|
//tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||||
// if let Err(err) = upload_file("tkt").await {
|
// if let Err(err) = upload_file("tkt").await {
|
||||||
// eprintln!("Error: {}", err);
|
// eprintln!("Error: {}", err);
|
||||||
|
Loading…
Reference in New Issue
Block a user