From 33d35aba496cd3003e4e83137f164ee2d5d82ef7 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Sun, 15 Sep 2024 21:27:03 +0200 Subject: [PATCH] feat(clone): created command clone --- src/commands/clone.rs | 34 ++++++++++++++++++++++++++++------ src/commands/test.rs | 12 ++++++------ src/main.rs | 5 +++-- src/services.rs | 4 +++- src/subcommands/clone.rs | 40 ++++++++++++++++++++++++++-------------- 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/src/commands/clone.rs b/src/commands/clone.rs index 88b3d02..308c34b 100644 --- a/src/commands/clone.rs +++ b/src/commands/clone.rs @@ -1,19 +1,41 @@ use crate::config::config::Config; +use crate::services::{service::Service, enumerator::Enumerator}; use regex::Regex; pub struct CloneArgs { pub remote: String, pub depth: Option, + pub force_insecure: bool, } -pub fn exec(args: CloneArgs, config: Config) { - get_url_props(&args.remote); +pub async fn exec(args: CloneArgs, config: Config) { + let mut url_props = get_url_props(&args.remote); + + if args.force_insecure { + url_props.is_secure = false; + } + + let service = Service::from(&url_props); + let Ok((files, folders)) = Enumerator::new(&service) + .set_path(url_props.path.to_string()) + // .set_depth(args.depth) + .get_properties(vec![]) + .enumerate().await else { todo!()}; + + for folder in folders { + // create folder + // save folder + } + + // let downloader = Downloader::new(&service, config.get_root_unsafe()) + // .set_files(files.map(|file| todo!())) + // .download(); } -struct UrlProps<'a> { - is_secure: bool, - domain: &'a str, - path: &'a str, +pub struct UrlProps<'a> { + pub is_secure: bool, + pub domain: &'a str, + pub path: &'a str, } impl UrlProps<'_> { diff --git a/src/commands/test.rs b/src/commands/test.rs index 7ce0fd1..33fb4a7 100644 --- a/src/commands/test.rs +++ b/src/commands/test.rs @@ -18,12 +18,12 @@ pub fn exec(args: TestArgs, config: Config) { // println!("{:?}", config); // Ok(()) - tokio::runtime::Runtime::new().unwrap().block_on(async { + // tokio::runtime::Runtime::new().unwrap().block_on(async { - let mut req = ReqProps::new("") - .set_config(&config) - .get_properties(vec![Props::CreationDate, Props::LastModified]); - req.send().await; - }); + // let mut req = ReqProps::new("") + // .set_config(&config) + // .get_properties(vec![Props::CreationDate, Props::LastModified]); + // req.send().await; + // }); // dbg!(req); } diff --git a/src/main.rs b/src/main.rs index d88c97a..a34a27a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,7 +7,8 @@ mod subcommands; mod utils; mod services; -fn main() { +#[tokio::main] +async fn main() { let app = Command::new("Nextsync") .version("1.0") .author("grimhilt") @@ -32,7 +33,7 @@ fn main() { Some(("reset", args)) => subcommands::reset::handler(args), Some(("push", args)) => subcommands::push::handler(args), Some(("test", args)) => subcommands::test::handler(args), - Some(("clone", args)) => subcommands::clone::handler(args), + Some(("clone", args)) => subcommands::clone::handler(args).await, Some((_, _)) => {} None => {} }; diff --git a/src/services.rs b/src/services.rs index 8bfeec3..cf5f687 100644 --- a/src/services.rs +++ b/src/services.rs @@ -1,2 +1,4 @@ -pub mod service; +pub mod downloader; +pub mod enumerator; pub mod req_props; +pub mod service; diff --git a/src/subcommands/clone.rs b/src/subcommands/clone.rs index 11e023f..13aafe5 100644 --- a/src/subcommands/clone.rs +++ b/src/subcommands/clone.rs @@ -1,18 +1,16 @@ -use clap::{Arg, Command, ArgMatches}; +use clap::{Arg, ArgMatches, Command}; use crate::commands; use crate::config::config::Config; pub fn create() -> Command { - // let remote_desc = sized_str(&format!("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories.")); - // let depth_desc = sized_str(&format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", clone::DEPTH)); Command::new("clone") .arg( Arg::new("remote") .required(true) .num_args(1) .value_name("REMOTE") - //.help(_desc) + .help("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories.") ) .arg( Arg::new("depth") @@ -20,8 +18,14 @@ pub fn create() -> Command { .long("depth") .required(false) .num_args(1) - //.help(&depth_desc) + .help(format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", crate::services::enumerator::DEFAULT_DEPTH)) ) + .arg( + Arg::new("force_insecure") + .long("force-insecure") + .short('f') + .help("Force the connection to nextcloud to be in http (not https)") + ) .arg( Arg::new("directory") .required(false) @@ -29,17 +33,25 @@ pub fn create() -> Command { .value_name("DIRECTORY") ) .about("Clone a repository into a new directory") - .after_help("NEXTSYNC URLS\nThe following syntaxes may be used:\n\t- user@host.xz/path/to/repo\n\t- http[s]://host.xz/apps/files/?dir=/path/to/repo&fileid=111111\n\t- [http[s]://]host.xz/remote.php/dav/files/user/path/to/repo\n") + .after_help(" +NEXTSYNC URLS +The following syntaxes may be used: + - [http[s]://]host.xz/apps/files/?dir=/path/to/repo&fileid=111111 + - [http[s]://]host.xz/path/to/repo + - [http[s]://]host.xz/remote.php/dav/files/user/path/to/repo +") } -pub fn handler(args: &ArgMatches) { - if let Some(val) = args.get_one::("directory") { - // global::global::set_dir_path(String::from(val.to_string())); - } +pub async fn handler(args: &ArgMatches) { if let Some(remote) = args.get_one::("remote") { - commands::clone::exec(commands::clone::CloneArgs { - remote: remote.to_string(), - depth: args.get_one::("depth").cloned(), - }, Config::new()); + commands::clone::exec( + commands::clone::CloneArgs { + remote: remote.to_string(), + depth: args.get_one::("depth").cloned(), + force_insecure: args.contains_id("force_insecure"), + }, + Config::from(args.get_one::("directory")), + ) + .await; } }