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::services::{service::Service, enumerator::Enumerator};
use regex::Regex;
pub struct CloneArgs {
pub remote: String,
pub depth: Option<String>,
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<'_> {

View File

@ -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);
}

View File

@ -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 => {}
};

View File

@ -1,2 +1,4 @@
pub mod service;
pub mod downloader;
pub mod enumerator;
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::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::<String>("directory") {
// global::global::set_dir_path(String::from(val.to_string()));
}
pub async fn handler(args: &ArgMatches) {
if let Some(remote) = args.get_one::<String>("remote") {
commands::clone::exec(commands::clone::CloneArgs {
remote: remote.to_string(),
depth: args.get_one::<String>("depth").cloned(),
}, Config::new());
commands::clone::exec(
commands::clone::CloneArgs {
remote: remote.to_string(),
depth: args.get_one::<String>("depth").cloned(),
force_insecure: args.contains_id("force_insecure"),
},
Config::from(args.get_one::<String>("directory")),
)
.await;
}
}