start add command

This commit is contained in:
grimhilt 2023-06-01 23:58:23 +02:00
parent 04bef223a3
commit f1724d23f5
5 changed files with 46 additions and 5 deletions

View File

@ -1,2 +1,3 @@
pub mod init;
pub mod status;
pub mod add;

18
src/commands/add.rs Normal file
View 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);
}
}

View File

@ -18,6 +18,13 @@ pub fn init() {
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.push(".nextsyncignore");
@ -26,5 +33,4 @@ pub fn init() {
Ok(_) => println!("File successfuly created"),
Err(_) => println!("Error: cannot create .nextsyncignore"),
}
}

View File

@ -9,9 +9,8 @@ use std::collections::HashSet;
use colored::Colorize;
use std::fs;
// todo: relative path, filename
// todo: relative path, filename, get modified
pub fn status() {
let mut new_files: Vec<PathBuf> = Vec::new();
let mut hashes = HashSet::new();
let mut objects: Vec<String> = vec![];

View File

@ -6,8 +6,9 @@
//use std::env;
//use dotenv::dotenv;
use clap::{App, SubCommand};
use clap::{App, Arg, SubCommand};
mod commands;
mod utils;
fn main() {
let matches = App::new("NextSync")
.version("1.0")
@ -15,14 +16,30 @@ fn main() {
.about("")
.subcommand(SubCommand::with_name("init"))
.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();
if let Some(_) = matches.subcommand_matches("init") {
commands::init::init();
} else if let Some(_) = matches.subcommand_matches("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 {
// if let Err(err) = upload_file("tkt").await {
// eprintln!("Error: {}", err);