add init when clone
This commit is contained in:
parent
5b7b75846c
commit
2117ce3016
@ -10,6 +10,7 @@ use xml::reader::{EventReader, XmlEvent};
|
|||||||
use crate::services::api::ApiError;
|
use crate::services::api::ApiError;
|
||||||
use crate::services::list_folders::ListFolders;
|
use crate::services::list_folders::ListFolders;
|
||||||
use crate::services::download_files::DownloadFiles;
|
use crate::services::download_files::DownloadFiles;
|
||||||
|
use crate::commands;
|
||||||
|
|
||||||
pub fn clone(remote: Values<'_>) {
|
pub fn clone(remote: Values<'_>) {
|
||||||
let url = remote.clone().next().unwrap();
|
let url = remote.clone().next().unwrap();
|
||||||
@ -49,7 +50,9 @@ pub fn clone(remote: Values<'_>) {
|
|||||||
// todo add second parameter to save in a folder
|
// todo add second parameter to save in a folder
|
||||||
eprintln!("fatal: directory already exist");
|
eprintln!("fatal: directory already exist");
|
||||||
// destination path 'path' already exists and is not an empty directory.
|
// destination path 'path' already exists and is not an empty directory.
|
||||||
//std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
} else {
|
||||||
|
commands::init::init(Some(env::current_dir().unwrap().to_str().unwrap()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let mut path = Path::new(&folder).strip_prefix("/remote.php/dav/files/");
|
let mut path = Path::new(&folder).strip_prefix("/remote.php/dav/files/");
|
||||||
|
@ -1,16 +1,22 @@
|
|||||||
use std::fs::{DirBuilder, File};
|
use std::fs::{DirBuilder, File};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use clap::Values;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
pub fn init() {
|
pub fn init(directory: Option<&str>) {
|
||||||
|
let mut path = match directory {
|
||||||
|
Some(dir) => PathBuf::from(dir),
|
||||||
|
None => env::current_dir().unwrap(),
|
||||||
|
};
|
||||||
let builder = DirBuilder::new();
|
let builder = DirBuilder::new();
|
||||||
let mut path = env::current_dir().unwrap();
|
// todo check if dir empty
|
||||||
|
|
||||||
// .nextsync folder
|
// .nextsync folder
|
||||||
path.push(".nextsync");
|
path.push(".nextsync");
|
||||||
match builder.create(path.clone()) {
|
match builder.create(path.clone()) {
|
||||||
Ok(()) => println!("Directory successfuly created"),
|
Ok(()) => println!("Directory successfuly created"),
|
||||||
Err(_) => println!("Error: cannot create directory"),
|
Err(_) => println!("Error: cannot create directory"),
|
||||||
}
|
};
|
||||||
|
|
||||||
path.push("HEAD");
|
path.push("HEAD");
|
||||||
match File::create(path.clone()) {
|
match File::create(path.clone()) {
|
||||||
|
33
src/main.rs
33
src/main.rs
@ -1,11 +1,3 @@
|
|||||||
//use reqwest::Client;
|
|
||||||
//use std::fs::File;
|
|
||||||
//use std::io::Read;
|
|
||||||
//use reqwest::header::{HeaderValue, CONTENT_TYPE, HeaderMap};
|
|
||||||
//use std::error::Error;
|
|
||||||
//use std::env;
|
|
||||||
//use dotenv::dotenv;
|
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
mod commands;
|
mod commands;
|
||||||
mod utils;
|
mod utils;
|
||||||
@ -15,7 +7,15 @@ fn main() {
|
|||||||
.version("1.0")
|
.version("1.0")
|
||||||
.author("grimhilt")
|
.author("grimhilt")
|
||||||
.about("")
|
.about("")
|
||||||
.subcommand(SubCommand::with_name("init"))
|
.subcommand(
|
||||||
|
SubCommand::with_name("init")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("directory")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("DIRECTORY")
|
||||||
|
)
|
||||||
|
)
|
||||||
.subcommand(SubCommand::with_name("status"))
|
.subcommand(SubCommand::with_name("status"))
|
||||||
.subcommand(SubCommand::with_name("reset"))
|
.subcommand(SubCommand::with_name("reset"))
|
||||||
.subcommand(
|
.subcommand(
|
||||||
@ -40,8 +40,11 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
if let Some(_) = matches.subcommand_matches("init") {
|
if let Some(matches) = matches.subcommand_matches("init") {
|
||||||
commands::init::init();
|
match matches.values_of("directory") {
|
||||||
|
Some(d) => commands::init::init(d.clone().next()),
|
||||||
|
None => commands::init::init(None),
|
||||||
|
}
|
||||||
} 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") {
|
} else if let Some(matches) = matches.subcommand_matches("add") {
|
||||||
@ -55,12 +58,4 @@ fn main() {
|
|||||||
commands::clone::clone(remote);
|
commands::clone::clone(remote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//tokio::runtime::Runtime::new().unwrap().block_on(async {
|
|
||||||
// if let Err(err) = upload_file("tkt").await {
|
|
||||||
// eprintln!("Error: {}", err);
|
|
||||||
// }
|
|
||||||
//});
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user