From 26153219b277408d2d8f09c0ca6a5c720cad2924 Mon Sep 17 00:00:00 2001 From: grimhilt Date: Thu, 8 Jun 2023 18:34:51 +0200 Subject: [PATCH] create folder method --- src/commands/push.rs | 15 ++++++++++++--- src/services/create_folder.rs | 28 ++++++++++++++++++++++++++++ src/utils/path.rs | 2 +- 3 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/services/create_folder.rs diff --git a/src/commands/push.rs b/src/commands/push.rs index a253c81..326a180 100644 --- a/src/commands/push.rs +++ b/src/commands/push.rs @@ -1,7 +1,16 @@ use crate::commands::{status, config}; pub fn push() { - dbg!(status::get_diff()); - let (staged_obj, new_obj, del_obj) = status::get_diff(); - dbg!(config::get("remote")); + dbg!(status::get_diff()); + + let remote = match config::get("remote") { + Some(r) => r, + None => { + eprintln!("fatal: no remote set in configuration"); + std::process::exit(1); + } + }; + let (staged_obj, new_obj, del_obj) = status::get_diff(); + + } diff --git a/src/services/create_folder.rs b/src/services/create_folder.rs new file mode 100644 index 0000000..a7d926a --- /dev/null +++ b/src/services/create_folder.rs @@ -0,0 +1,28 @@ +use crate::services::api::{ApiBuilder, ApiError}; +use reqwest::{Method, IntoUrl, Response, Error}; + +pub struct CreateFolder { + api_builder: ApiBuilder, +} + +impl CreateFolder { + pub fn new(url: U) -> Self { + ListFolders { + api_builder: ApiBuilder::new() + .set_request(Method::from_bytes(b"MKCOL").unwrap(), url), + } + } + + pub async fn send(&mut self) -> Result { + self.api_builder.send().await + } + + pub async fn send_with_err(mut self) -> Result<(), ApiError> { + let res = self.send().await.map_err(ApiError::RequestError)?; + if res.status().is_success() { + Ok() + } else { + Err(ApiError::IncorrectRequest(res)) + } + } +} diff --git a/src/utils/path.rs b/src/utils/path.rs index de183c7..d799164 100644 --- a/src/utils/path.rs +++ b/src/utils/path.rs @@ -14,7 +14,7 @@ pub fn current() -> Option { } else { let current_dir = env::current_dir().ok()?; let abs = current_dir.join(tmp); - let canonicalized_path = canonicalize(abs).ok()?; + let canonicalized_path = canonicalize(abs).ok()?; Some(canonicalized_path) }