start clone get info folder

This commit is contained in:
grimhilt 2023-06-04 18:12:47 +02:00
parent 0817e01bdf
commit f398347856
4 changed files with 46 additions and 0 deletions

View File

@ -2,3 +2,4 @@ pub mod init;
pub mod status;
pub mod add;
pub mod reset;
pub mod clone;

28
src/commands/clone.rs Normal file
View File

@ -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<String, Box<dyn Error>> {
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(())
}

View File

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

2
src/services.rs Normal file
View File

@ -0,0 +1,2 @@
pub mod api;
pub mod list_folders;