feat(clone): created command clone

This commit is contained in:
grimhilt 2024-09-15 21:27:03 +02:00
parent adac2e6cda
commit 33d35aba49
5 changed files with 66 additions and 29 deletions

View File

@ -1,19 +1,41 @@
use crate::config::config::Config; use crate::config::config::Config;
use crate::services::{service::Service, enumerator::Enumerator};
use regex::Regex; use regex::Regex;
pub struct CloneArgs { pub struct CloneArgs {
pub remote: String, pub remote: String,
pub depth: Option<String>, pub depth: Option<String>,
pub force_insecure: bool,
} }
pub fn exec(args: CloneArgs, config: Config) { pub async fn exec(args: CloneArgs, config: Config) {
get_url_props(&args.remote); 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> { pub struct UrlProps<'a> {
is_secure: bool, pub is_secure: bool,
domain: &'a str, pub domain: &'a str,
path: &'a str, pub path: &'a str,
} }
impl UrlProps<'_> { impl UrlProps<'_> {

View File

@ -18,12 +18,12 @@ pub fn exec(args: TestArgs, config: Config) {
// println!("{:?}", config); // println!("{:?}", config);
// Ok(()) // Ok(())
tokio::runtime::Runtime::new().unwrap().block_on(async { // tokio::runtime::Runtime::new().unwrap().block_on(async {
let mut req = ReqProps::new("") // let mut req = ReqProps::new("")
.set_config(&config) // .set_config(&config)
.get_properties(vec![Props::CreationDate, Props::LastModified]); // .get_properties(vec![Props::CreationDate, Props::LastModified]);
req.send().await; // req.send().await;
}); // });
// dbg!(req); // dbg!(req);
} }

View File

@ -7,7 +7,8 @@ mod subcommands;
mod utils; mod utils;
mod services; mod services;
fn main() { #[tokio::main]
async fn main() {
let app = Command::new("Nextsync") let app = Command::new("Nextsync")
.version("1.0") .version("1.0")
.author("grimhilt") .author("grimhilt")
@ -32,7 +33,7 @@ fn main() {
Some(("reset", args)) => subcommands::reset::handler(args), Some(("reset", args)) => subcommands::reset::handler(args),
Some(("push", args)) => subcommands::push::handler(args), Some(("push", args)) => subcommands::push::handler(args),
Some(("test", args)) => subcommands::test::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((_, _)) => {} Some((_, _)) => {}
None => {} None => {}
}; };

View File

@ -1,2 +1,4 @@
pub mod service; pub mod downloader;
pub mod enumerator;
pub mod req_props; pub mod req_props;
pub mod service;

View File

@ -1,18 +1,16 @@
use clap::{Arg, Command, ArgMatches}; use clap::{Arg, ArgMatches, Command};
use crate::commands; use crate::commands;
use crate::config::config::Config; use crate::config::config::Config;
pub fn create() -> Command { 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") Command::new("clone")
.arg( .arg(
Arg::new("remote") Arg::new("remote")
.required(true) .required(true)
.num_args(1) .num_args(1)
.value_name("REMOTE") .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(
Arg::new("depth") Arg::new("depth")
@ -20,7 +18,13 @@ pub fn create() -> Command {
.long("depth") .long("depth")
.required(false) .required(false)
.num_args(1) .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(
Arg::new("directory") Arg::new("directory")
@ -29,17 +33,25 @@ pub fn create() -> Command {
.value_name("DIRECTORY") .value_name("DIRECTORY")
) )
.about("Clone a repository into a new 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) { pub async fn handler(args: &ArgMatches) {
if let Some(val) = args.get_one::<String>("directory") {
// global::global::set_dir_path(String::from(val.to_string()));
}
if let Some(remote) = args.get_one::<String>("remote") { if let Some(remote) = args.get_one::<String>("remote") {
commands::clone::exec(commands::clone::CloneArgs { commands::clone::exec(
commands::clone::CloneArgs {
remote: remote.to_string(), remote: remote.to_string(),
depth: args.get_one::<String>("depth").cloned(), depth: args.get_one::<String>("depth").cloned(),
}, Config::new()); force_insecure: args.contains_id("force_insecure"),
},
Config::from(args.get_one::<String>("directory")),
)
.await;
} }
} }