diff --git a/src/commands/remote_diff.rs b/src/commands/remote_diff.rs index b0c90ba..aae905f 100644 --- a/src/commands/remote_diff.rs +++ b/src/commands/remote_diff.rs @@ -1,52 +1,17 @@ use crate::services::api::ApiError; use crate::services::req_props::{ReqProps, ObjProps}; -use crate::store::object::{Object, self}; +use crate::store::object::Object; use crate::utils::api::{ApiProps, get_api_props}; use crate::utils::path; use crate::utils::remote::{enumerate_remote, EnumerateOptions}; -use std::fs::canonicalize; use std::path::PathBuf; -pub struct RemoteDiffArgs { - pub path: Option, -} - -pub fn remote_diff(args: RemoteDiffArgs) { - let path = { - if let Some(path) = args.path { - let mut cur = path::current().unwrap(); - cur.push(path); - let canonic = canonicalize(cur).ok().unwrap(); - dbg!(&canonic); - dbg!(path::repo_root()); - let ok = canonic.strip_prefix(path::repo_root()); - dbg!(&ok); - - // todo - PathBuf::from("/") - } else { - PathBuf::from("/") - } - }; - - let mut folders: Vec = vec![ObjProps { - contentlength: None, - href: None, - lastmodified: None, - relative_s: Some(path.to_str().unwrap().to_owned()), - }]; - let mut files: Vec = vec![]; - - let depth = "2"; // todo - // todo origin - let api_props = get_api_props(); - let (folders, files) = enumerate_remote( - |a| req(&api_props, depth, a), - &should_skip, - EnumerateOptions { - depth: Some(depth.to_owned()), - relative_s: Some(path.to_str().unwrap().to_owned()) - }); +// todo deletion +pub fn remote_diff() { + let relative_p = path::current() + .unwrap() + .strip_prefix(path::repo_root()).unwrap().to_path_buf(); + let (folders, files) = get_diff(relative_p); for folder in folders { println!("should pull {}", folder.clone().relative_s.unwrap()); @@ -54,7 +19,20 @@ pub fn remote_diff(args: RemoteDiffArgs) { for file in files { println!("should pull {}", file.clone().relative_s.unwrap()); } +} +pub fn get_diff(path: PathBuf) -> (Vec, Vec) { + + let depth = "2"; // todo + let api_props = get_api_props(); + + enumerate_remote( + |a| req(&api_props, depth, a), + &should_skip, + EnumerateOptions { + depth: Some(depth.to_owned()), + relative_s: Some(path.to_str().unwrap().to_owned()) + }) } fn should_skip(obj: ObjProps) -> bool { diff --git a/src/main.rs b/src/main.rs index b79361b..736c4e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,6 @@ use clap::{App, Arg, SubCommand}; use textwrap::{fill, Options}; use crate::commands::add::AddArgs; -use crate::commands::remote_diff::RemoteDiffArgs; use crate::commands::clone::{self, CloneArgs}; mod commands; @@ -168,18 +167,15 @@ fn main() { } } } else if let Some(matches) = matches.subcommand_matches("remote-diff") { - commands::remote_diff::remote_diff(RemoteDiffArgs { - path: { - if let Some(mut path) = matches.values_of("path") { - match path.next() { - Some(p) => Some(String::from(p)), - None => None, - } - } else { - None - } - }, - }); + if let Some(val) = matches.values_of("path") { + global::global::set_dir_path(String::from(val.clone().next().unwrap())); + } + commands::remote_diff::remote_diff(); + } else if let Some(matches) = matches.subcommand_matches("pull") { + if let Some(val) = matches.values_of("path") { + global::global::set_dir_path(String::from(val.clone().next().unwrap())); + } + commands::pull::pull(); } else if let Some(_) = matches.subcommand_matches("test") { }