remote-diff only a directory

This commit is contained in:
grimhilt 2023-07-28 13:22:13 +02:00
parent 29def4967c
commit 4c34df7cfe
2 changed files with 29 additions and 55 deletions

View File

@ -1,52 +1,17 @@
use crate::services::api::ApiError; use crate::services::api::ApiError;
use crate::services::req_props::{ReqProps, ObjProps}; 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::api::{ApiProps, get_api_props};
use crate::utils::path; use crate::utils::path;
use crate::utils::remote::{enumerate_remote, EnumerateOptions}; use crate::utils::remote::{enumerate_remote, EnumerateOptions};
use std::fs::canonicalize;
use std::path::PathBuf; use std::path::PathBuf;
pub struct RemoteDiffArgs { // todo deletion
pub path: Option<String>, pub fn remote_diff() {
} let relative_p = path::current()
.unwrap()
pub fn remote_diff(args: RemoteDiffArgs) { .strip_prefix(path::repo_root()).unwrap().to_path_buf();
let path = { let (folders, files) = get_diff(relative_p);
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<ObjProps> = vec![ObjProps {
contentlength: None,
href: None,
lastmodified: None,
relative_s: Some(path.to_str().unwrap().to_owned()),
}];
let mut files: Vec<ObjProps> = 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())
});
for folder in folders { for folder in folders {
println!("should pull {}", folder.clone().relative_s.unwrap()); println!("should pull {}", folder.clone().relative_s.unwrap());
@ -54,7 +19,20 @@ pub fn remote_diff(args: RemoteDiffArgs) {
for file in files { for file in files {
println!("should pull {}", file.clone().relative_s.unwrap()); println!("should pull {}", file.clone().relative_s.unwrap());
} }
}
pub fn get_diff(path: PathBuf) -> (Vec<ObjProps>, Vec<ObjProps>) {
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 { fn should_skip(obj: ObjProps) -> bool {

View File

@ -2,7 +2,6 @@ use clap::{App, Arg, SubCommand};
use textwrap::{fill, Options}; use textwrap::{fill, Options};
use crate::commands::add::AddArgs; use crate::commands::add::AddArgs;
use crate::commands::remote_diff::RemoteDiffArgs;
use crate::commands::clone::{self, CloneArgs}; use crate::commands::clone::{self, CloneArgs};
mod commands; mod commands;
@ -168,18 +167,15 @@ fn main() {
} }
} }
} else if let Some(matches) = matches.subcommand_matches("remote-diff") { } else if let Some(matches) = matches.subcommand_matches("remote-diff") {
commands::remote_diff::remote_diff(RemoteDiffArgs { if let Some(val) = matches.values_of("path") {
path: { global::global::set_dir_path(String::from(val.clone().next().unwrap()));
if let Some(mut path) = matches.values_of("path") { }
match path.next() { commands::remote_diff::remote_diff();
Some(p) => Some(String::from(p)), } else if let Some(matches) = matches.subcommand_matches("pull") {
None => None, if let Some(val) = matches.values_of("path") {
} global::global::set_dir_path(String::from(val.clone().next().unwrap()));
} else { }
None commands::pull::pull();
}
},
});
} else if let Some(_) = matches.subcommand_matches("test") { } else if let Some(_) = matches.subcommand_matches("test") {
} }