diff --git a/src/commands.rs b/src/commands.rs index 5066f6a..7514331 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -2,3 +2,4 @@ pub mod init; pub mod status; pub mod add; pub mod reset; +pub mod clone; diff --git a/src/commands/clone.rs b/src/commands/clone.rs new file mode 100644 index 0000000..dccaff4 --- /dev/null +++ b/src/commands/clone.rs @@ -0,0 +1,28 @@ +use clap::Values; +use std::fs::{self, DirBuilder}; +use std::path::Path; +use crate::services::list_folders::ListFolders; +use std::error::Error; + +pub fn clone(remote: Values<'_>) { + let url = remote.clone().next().unwrap(); + let path = Path::new(url); + + tokio::runtime::Runtime::new().unwrap().block_on(async { + call(url).await + }); + //DirBuilder::new() + // .create(path.parent()); +} + +pub async fn call(url: &str) -> Result> { + let response = ListFolders::new(url).send().await?; + if response.status().is_success() { + let body = response.text().await?; + println!("Response body: {}", body); + } else { + println!("Request failed with status code: {}", response.status()); + } + Ok(()) +} + diff --git a/src/main.rs b/src/main.rs index ad9ef90..0091515 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ use clap::{App, Arg, SubCommand}; mod commands; mod utils; +mod services; fn main() { let matches = App::new("NextSync") .version("1.0") @@ -17,6 +18,15 @@ fn main() { .subcommand(SubCommand::with_name("init")) .subcommand(SubCommand::with_name("status")) .subcommand(SubCommand::with_name("reset")) + .subcommand( + SubCommand::with_name("clone") + .arg( + Arg::with_name("remote") + .required(true) + .takes_value(true) + .value_name("REMOTE") + ) + ) .subcommand( SubCommand::with_name("add") .arg( @@ -40,9 +50,14 @@ fn main() { } } else if let Some(_) = matches.subcommand_matches("reset") { commands::reset::reset(); + } else if let Some(matches) = matches.subcommand_matches("clone") { + if let Some(remote) = matches.values_of("remote") { + commands::clone::clone(remote); + } } + //tokio::runtime::Runtime::new().unwrap().block_on(async { // if let Err(err) = upload_file("tkt").await { // eprintln!("Error: {}", err); diff --git a/src/services.rs b/src/services.rs new file mode 100644 index 0000000..73824d5 --- /dev/null +++ b/src/services.rs @@ -0,0 +1,2 @@ +pub mod api; +pub mod list_folders;