Compare commits
No commits in common. "7719e27fe8ba00cf33177ff11120b2eef5460da6" and "81c24b5e3c64d8c50d242bb8000f6f26183a60d6" have entirely different histories.
7719e27fe8
...
81c24b5e3c
@ -5,7 +5,7 @@ use clap::Values;
|
|||||||
use glob::glob;
|
use glob::glob;
|
||||||
use crate::store::index;
|
use crate::store::index;
|
||||||
use crate::store::{self, object::Object};
|
use crate::store::{self, object::Object};
|
||||||
use crate::utils::{self, path};
|
use crate::utils;
|
||||||
use crate::utils::nextsyncignore::{self, ignore_file};
|
use crate::utils::nextsyncignore::{self, ignore_file};
|
||||||
use crate::utils::path::{normalize_relative, repo_root, path_buf_to_string};
|
use crate::utils::path::{normalize_relative, repo_root, path_buf_to_string};
|
||||||
|
|
||||||
@ -19,21 +19,17 @@ pub struct AddArgs<'a> {
|
|||||||
|
|
||||||
// todo match deleted files
|
// todo match deleted files
|
||||||
pub fn add(args: AddArgs) {
|
pub fn add(args: AddArgs) {
|
||||||
|
// write all modification in the index
|
||||||
let mut pattern: String;
|
if args.all {
|
||||||
let file_vec: Vec<&str> = match args.all {
|
write_all();
|
||||||
true => {
|
return;
|
||||||
pattern = path_buf_to_string(repo_root());
|
}
|
||||||
pattern.push_str("/*");
|
|
||||||
vec![&pattern]
|
|
||||||
},
|
|
||||||
false => args.files.unwrap().collect(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut added_files: Vec<String> = vec![];
|
let mut added_files: Vec<String> = vec![];
|
||||||
let mut ignored_f = vec![];
|
let mut ignored_f = vec![];
|
||||||
let rules = nextsyncignore::get_rules();
|
let rules = nextsyncignore::get_rules();
|
||||||
|
|
||||||
|
let file_vec: Vec<&str> = args.files.unwrap().collect();
|
||||||
for file in file_vec {
|
for file in file_vec {
|
||||||
let f = match normalize_relative(file) {
|
let f = match normalize_relative(file) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
@ -62,9 +58,6 @@ pub fn add(args: AddArgs) {
|
|||||||
added_files.push(String::from(f));
|
added_files.push(String::from(f));
|
||||||
} else {
|
} else {
|
||||||
for entry in try_globbing(path) {
|
for entry in try_globbing(path) {
|
||||||
if path::is_nextsync_config(entry.clone()) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if !args.force && ignore_file(&path_buf_to_string(entry.clone()), rules.clone(), &mut ignored_f) {
|
if !args.force && ignore_file(&path_buf_to_string(entry.clone()), rules.clone(), &mut ignored_f) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -132,16 +125,22 @@ fn add_folder_content(path: PathBuf, added_files: &mut Vec<String>) {
|
|||||||
if let Ok(entries) = utils::read::read_folder(folder.clone()) {
|
if let Ok(entries) = utils::read::read_folder(folder.clone()) {
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
let path_entry = PathBuf::from(entry);
|
let path_entry = PathBuf::from(entry);
|
||||||
if !path::is_nextsync_config(path_entry.clone())
|
|
||||||
{
|
|
||||||
if path_entry.is_dir() {
|
if path_entry.is_dir() {
|
||||||
folders.push(path_entry.clone());
|
folders.push(path_entry.clone());
|
||||||
}
|
}
|
||||||
added_files.push(path_buf_to_string(path_entry.strip_prefix(repo_root()).unwrap().to_path_buf()));
|
added_files.push(String::from(path_entry.to_str().unwrap()));
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn write_all() {
|
||||||
|
let objs = get_all_objs();
|
||||||
|
let mut index_file = OpenOptions::new()
|
||||||
|
.write(true)
|
||||||
|
.create(true)
|
||||||
|
.open(index::path()).expect("Cannot open index file");
|
||||||
|
for obj in objs {
|
||||||
|
let _ = writeln!(index_file, "{}", path_buf_to_string(obj.path.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -95,7 +95,7 @@ fn should_retain(hasher: &mut Sha1, key: String, obj: LocalObj, move_copy_hashes
|
|||||||
// todo deal with directories
|
// todo deal with directories
|
||||||
if obj.path.is_dir()
|
if obj.path.is_dir()
|
||||||
{
|
{
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
let mut blob = Blob::new(obj.path.clone());
|
let mut blob = Blob::new(obj.path.clone());
|
||||||
let mut flag = true;
|
let mut flag = true;
|
||||||
@ -329,7 +329,7 @@ fn add_to_hashmap(lines: Lines<BufReader<File>>, hashes: &mut HashMap<String, Lo
|
|||||||
|
|
||||||
fn add_to_vec(entries: Vec<PathBuf>, objects: &mut Vec<String>, root: PathBuf) {
|
fn add_to_vec(entries: Vec<PathBuf>, objects: &mut Vec<String>, root: PathBuf) {
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
if !path::is_nextsync_config(entry.clone()) {
|
if !is_nextsync_config(entry.clone()) {
|
||||||
let object_path = entry.strip_prefix(root.clone()).unwrap();
|
let object_path = entry.strip_prefix(root.clone()).unwrap();
|
||||||
objects.push(String::from(object_path.to_str().unwrap()));
|
objects.push(String::from(object_path.to_str().unwrap()));
|
||||||
}
|
}
|
||||||
@ -441,6 +441,10 @@ fn remove_duplicate(hashes: &mut HashMap<String, LocalObj>, objects: &mut Vec<St
|
|||||||
duplicate
|
duplicate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn is_nextsync_config(path: PathBuf) -> bool {
|
||||||
|
path.ends_with(".nextsync")
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
214
src/main.rs
214
src/main.rs
@ -1,6 +1,9 @@
|
|||||||
use clap::{App, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
|
use textwrap::{fill, Options};
|
||||||
|
|
||||||
mod subcommands;
|
use crate::commands::add::AddArgs;
|
||||||
|
use crate::commands::status::StatusArgs;
|
||||||
|
use crate::commands::clone::{self, CloneArgs};
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
mod utils;
|
mod utils;
|
||||||
@ -9,38 +12,193 @@ mod global;
|
|||||||
mod store;
|
mod store;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = App::new("Nextsync")
|
let matches = App::new("Nextsync")
|
||||||
.version("1.0")
|
.version("1.0")
|
||||||
.author("grimhilt")
|
.author("grimhilt")
|
||||||
.about("A git-line command line tool to interact with nextcloud")
|
.about("A git-line command line tool to interact with nextcloud")
|
||||||
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||||
.subcommand(subcommands::clone::create())
|
.subcommand(
|
||||||
.subcommand(subcommands::init::create())
|
SubCommand::with_name("clone")
|
||||||
.subcommand(subcommands::status::create())
|
.arg(
|
||||||
.subcommand(subcommands::add::create())
|
Arg::with_name("remote")
|
||||||
.subcommand(subcommands::push::create())
|
.required(true)
|
||||||
.subcommand(subcommands::reset::create())
|
.takes_value(true)
|
||||||
.subcommand(subcommands::config::create())
|
.value_name("REMOTE")
|
||||||
.subcommand(subcommands::remote_diff::create())
|
.help(&fill(
|
||||||
.subcommand(subcommands::pull::create())
|
"The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories.",
|
||||||
|
Options::new(70).width,
|
||||||
|
))
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("depth")
|
||||||
|
.short("d")
|
||||||
|
.long("depth")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(true)
|
||||||
|
.help(&fill(
|
||||||
|
&format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", clone::DEPTH),
|
||||||
|
Options::new(70).width,
|
||||||
|
))
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("directory")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("DIRECTORY")
|
||||||
|
)
|
||||||
|
.about("Clone a repository into a new directory")
|
||||||
|
.after_help("NEXTSYNC URLS\nThe following syntaxes may be used:\n\t- user@host.xz/path/to/repo\n\t- http[s]://host.xz/apps/files/?dir=/path/to/repo&fileid=111111\n\t- [http[s]://]host.xz/remote.php/dav/files/user/path/to/repo\n")
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("init")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("directory")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("DIRECTORY")
|
||||||
|
)
|
||||||
|
.about("Create an empty Nextsync repository") // Create an empty Git repository or reinitialize an existing one
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("status")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("directory")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("DIRECTORY")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("nostyle")
|
||||||
|
.long("nostyle")
|
||||||
|
.help("Status with minium information and style"),
|
||||||
|
)
|
||||||
|
.about("Show the working tree status")
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("reset")
|
||||||
|
.about("Clear the index")
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("push")
|
||||||
|
.about("Push changes on nextcloud")
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("add")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("files")
|
||||||
|
.required(true)
|
||||||
|
.conflicts_with("all")
|
||||||
|
.multiple(true)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("FILE")
|
||||||
|
.help("Files to add"),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("force")
|
||||||
|
.short("f")
|
||||||
|
.long("force")
|
||||||
|
.help("Allow adding otherwise ignored files."),
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("all")
|
||||||
|
.short("A")
|
||||||
|
.long("all")
|
||||||
|
.help("This adds, modifies, and removes index entries to match the working tree"),
|
||||||
|
)
|
||||||
|
.about("Add changes to the index")
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("config")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("variable")
|
||||||
|
.required(true)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("VARIABLE")
|
||||||
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("value")
|
||||||
|
.required(true)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("VALUE")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.subcommand(
|
||||||
|
SubCommand::with_name("remote-diff")
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("path")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("PATH")
|
||||||
|
.help("The path to pull."),
|
||||||
|
)
|
||||||
|
.about("Fetch new and modifed files from the nextcloud server.")
|
||||||
|
)
|
||||||
.subcommand(
|
.subcommand(
|
||||||
SubCommand::with_name("test")
|
SubCommand::with_name("test")
|
||||||
);
|
)
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
let matches = app.get_matches();
|
if let Some(matches) = matches.subcommand_matches("init") {
|
||||||
|
if let Some(val) = matches.values_of("directory") {
|
||||||
match matches.subcommand() {
|
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
||||||
("init", Some(args)) => subcommands::init::handler(args),
|
}
|
||||||
("status", Some(args)) => subcommands::status::handler(args),
|
commands::init::init();
|
||||||
("add", Some(args)) => subcommands::add::handler(args),
|
} else if let Some(matches) = matches.subcommand_matches("status") {
|
||||||
("reset", Some(_)) => commands::reset::reset(),
|
if let Some(val) = matches.values_of("directory") {
|
||||||
("clone", Some(args)) => subcommands::clone::handler(args),
|
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
||||||
("push", Some(_)) => commands::push::push(),
|
}
|
||||||
("config", Some(args)) => subcommands::config::handler(args),
|
commands::status::status(StatusArgs {
|
||||||
("remote-diff", Some(args)) => subcommands::remote_diff::handler(args),
|
nostyle: matches.is_present("nostyle"),
|
||||||
("pull", Some(args)) => subcommands::pull::handler(args),
|
});
|
||||||
|
} else if let Some(matches) = matches.subcommand_matches("add") {
|
||||||
(_, _) => {},
|
if let Some(files) = matches.values_of("files") {
|
||||||
};
|
commands::add::add(AddArgs {
|
||||||
|
files: Some(files),
|
||||||
|
force: matches.is_present("force"),
|
||||||
|
all: matches.is_present("all"),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
commands::add::add(AddArgs {
|
||||||
|
files: None,
|
||||||
|
force: matches.is_present("force"),
|
||||||
|
all: matches.is_present("all"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if let Some(_) = matches.subcommand_matches("reset") {
|
||||||
|
commands::reset::reset();
|
||||||
|
} else if let Some(matches) = matches.subcommand_matches("clone") {
|
||||||
|
if let Some(val) = matches.values_of("directory") {
|
||||||
|
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
||||||
|
}
|
||||||
|
if let Some(remote) = matches.values_of("remote") {
|
||||||
|
commands::clone::clone(CloneArgs {
|
||||||
|
remote,
|
||||||
|
depth: matches.values_of("depth").map(
|
||||||
|
|mut val| val.next().unwrap().to_owned()
|
||||||
|
),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else if let Some(_matches) = matches.subcommand_matches("push") {
|
||||||
|
commands::push::push();
|
||||||
|
} else if let Some(matches) = matches.subcommand_matches("config") {
|
||||||
|
if let Some(mut var) = matches.values_of("variable") {
|
||||||
|
if let Some(mut val) = matches.values_of("value") {
|
||||||
|
if commands::config::set(var.next().unwrap(), val.next().unwrap()).is_err() {
|
||||||
|
eprintln!("fatal: cannot save the value");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if let Some(matches) = matches.subcommand_matches("remote-diff") {
|
||||||
|
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") {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use reqwest::{Method, header::HeaderValue};
|
use reqwest::{Method, header::HeaderValue};
|
||||||
use crate::services::api::{ApiBuilder, ApiError};
|
use crate::services::api::{ApiBuilder, ApiError};
|
||||||
use crate::commands::clone::get_url_props;
|
use crate::clone::get_url_props;
|
||||||
use crate::commands::config;
|
use crate::commands::config;
|
||||||
use crate::services::api_call::ApiCall;
|
use crate::services::api_call::ApiCall;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use reqwest::{Method, header::HeaderValue};
|
use reqwest::{Method, header::HeaderValue};
|
||||||
use crate::services::api::{ApiBuilder, ApiError};
|
use crate::services::api::{ApiBuilder, ApiError};
|
||||||
use crate::commands::clone::get_url_props;
|
use crate::clone::get_url_props;
|
||||||
use crate::commands::config;
|
use crate::commands::config;
|
||||||
use crate::services::api_call::ApiCall;
|
use crate::services::api_call::ApiCall;
|
||||||
|
|
||||||
|
@ -76,4 +76,9 @@ impl RequestManager {
|
|||||||
|
|
||||||
self.token.clone().unwrap()
|
self.token.clone().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_request()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
pub mod init;
|
|
||||||
pub mod status;
|
|
||||||
pub mod add;
|
|
||||||
pub mod reset;
|
|
||||||
pub mod clone;
|
|
||||||
pub mod push;
|
|
||||||
pub mod config;
|
|
||||||
pub mod remote_diff;
|
|
||||||
pub mod pull;
|
|
@ -1,38 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand, ArgMatches};
|
|
||||||
|
|
||||||
use crate::commands;
|
|
||||||
use crate::commands::add::AddArgs;
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("add")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("files")
|
|
||||||
.required(true)
|
|
||||||
.conflicts_with("all")
|
|
||||||
.multiple(true)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("FILE")
|
|
||||||
.help("Files to add"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("force")
|
|
||||||
.short("f")
|
|
||||||
.long("force")
|
|
||||||
.help("Allow adding otherwise ignored files."),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("all")
|
|
||||||
.short("A")
|
|
||||||
.long("all")
|
|
||||||
.help("This adds, modifies, and removes index entries to match the working tree"),
|
|
||||||
)
|
|
||||||
.about("Add changes to the index")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handler(args: &ArgMatches<'_>) {
|
|
||||||
commands::add::add(AddArgs {
|
|
||||||
files: args.values_of("files"),
|
|
||||||
force: args.is_present("force"),
|
|
||||||
all: args.is_present("all"),
|
|
||||||
});
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand, ArgMatches};
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use textwrap::{fill, Options};
|
|
||||||
|
|
||||||
use crate::commands::clone::{self, CloneArgs};
|
|
||||||
use crate::global;
|
|
||||||
use crate::commands;
|
|
||||||
|
|
||||||
fn sized_str<'a>(content: &'a str) -> &'a str {
|
|
||||||
fill(content, Options::new(70).width).as_str();
|
|
||||||
"ok"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn test() -> String {
|
|
||||||
String::from("ok")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
let remote_desc = sized_str(&format!("The repository to clone from. See the NEXTSYNC URLS section below for more information on specifying repositories."));
|
|
||||||
let depth_desc = sized_str(&format!("Depth of the recursive fetch of object properties. This value should be lower when there are a lot of files per directory and higher when there are a lot of subdirectories with fewer files. (Default: {})", clone::DEPTH));
|
|
||||||
SubCommand::with_name("clone")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("remote")
|
|
||||||
.required(true)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("REMOTE")
|
|
||||||
//.help(_desc)
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("depth")
|
|
||||||
.short("d")
|
|
||||||
.long("depth")
|
|
||||||
.required(false)
|
|
||||||
.takes_value(true)
|
|
||||||
//.help(&depth_desc)
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("directory")
|
|
||||||
.required(false)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("DIRECTORY")
|
|
||||||
)
|
|
||||||
.about("Clone a repository into a new directory")
|
|
||||||
.after_help("NEXTSYNC URLS\nThe following syntaxes may be used:\n\t- user@host.xz/path/to/repo\n\t- http[s]://host.xz/apps/files/?dir=/path/to/repo&fileid=111111\n\t- [http[s]://]host.xz/remote.php/dav/files/user/path/to/repo\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handler(args: &ArgMatches<'_>) {
|
|
||||||
if let Some(val) = args.values_of("directory") {
|
|
||||||
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
|
||||||
}
|
|
||||||
if let Some(remote) = args.values_of("remote") {
|
|
||||||
commands::clone::clone(CloneArgs {
|
|
||||||
remote,
|
|
||||||
depth: args.values_of("depth").map(
|
|
||||||
|mut val| val.next().unwrap().to_owned()
|
|
||||||
),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand, ArgMatches};
|
|
||||||
|
|
||||||
use crate::commands;
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("config")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("variable")
|
|
||||||
.required(true)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("VARIABLE")
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("value")
|
|
||||||
.required(true)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("VALUE")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handler(args: &ArgMatches<'_>) {
|
|
||||||
if let Some(mut var) = args.values_of("variable") {
|
|
||||||
if let Some(mut val) = args.values_of("value") {
|
|
||||||
if commands::config::set(var.next().unwrap(), val.next().unwrap()).is_err() {
|
|
||||||
eprintln!("fatal: cannot save the value");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand, ArgMatches};
|
|
||||||
|
|
||||||
use crate::global;
|
|
||||||
use crate::commands;
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("init")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("directory")
|
|
||||||
.required(false)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("DIRECTORY")
|
|
||||||
)
|
|
||||||
.about("Create an empty Nextsync repository")
|
|
||||||
// Create an empty nextsync repository or reinitialize an existing one
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handler(args: &ArgMatches<'_>) {
|
|
||||||
if let Some(val) = args.values_of("directory") {
|
|
||||||
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
|
||||||
}
|
|
||||||
commands::init::init();
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand, ArgMatches};
|
|
||||||
|
|
||||||
use crate::global;
|
|
||||||
use crate::commands;
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("pull")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("path")
|
|
||||||
.required(false)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("PATH")
|
|
||||||
.help("The path to pull."),
|
|
||||||
)
|
|
||||||
.about("Fetch and integrate changes from the nextcloud server.")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handler(args: &ArgMatches<'_>) {
|
|
||||||
if let Some(val) = args.values_of("path") {
|
|
||||||
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
|
||||||
}
|
|
||||||
commands::pull::pull();
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand};
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("push")
|
|
||||||
.about("Push changes on nextcloud")
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand, ArgMatches};
|
|
||||||
|
|
||||||
use crate::global;
|
|
||||||
use crate::commands;
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("remote-diff")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("path")
|
|
||||||
.required(false)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("PATH")
|
|
||||||
.help("The path to pull."),
|
|
||||||
)
|
|
||||||
.about("Fetch changes from the nextcloud server.")
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub fn handler(args: &ArgMatches<'_>) {
|
|
||||||
if let Some(val) = args.values_of("path") {
|
|
||||||
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
|
||||||
}
|
|
||||||
commands::remote_diff::remote_diff();
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand};
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("reset")
|
|
||||||
.about("Clear the index")
|
|
||||||
}
|
|
@ -1,30 +0,0 @@
|
|||||||
use clap::{App, Arg, SubCommand, ArgMatches};
|
|
||||||
|
|
||||||
use crate::global;
|
|
||||||
use crate::commands;
|
|
||||||
use crate::commands::status::StatusArgs;
|
|
||||||
|
|
||||||
pub fn create() -> App<'static, 'static> {
|
|
||||||
SubCommand::with_name("status")
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("directory")
|
|
||||||
.required(false)
|
|
||||||
.takes_value(true)
|
|
||||||
.value_name("DIRECTORY")
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("nostyle")
|
|
||||||
.long("nostyle")
|
|
||||||
.help("Status with minium information and style"),
|
|
||||||
)
|
|
||||||
.about("Show the working tree status")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn handler(args: &ArgMatches<'_>) {
|
|
||||||
if let Some(val) = args.values_of("directory") {
|
|
||||||
global::global::set_dir_path(String::from(val.clone().next().unwrap()));
|
|
||||||
}
|
|
||||||
commands::status::status(StatusArgs {
|
|
||||||
nostyle: args.is_present("nostyle"),
|
|
||||||
});
|
|
||||||
}
|
|
@ -104,10 +104,6 @@ pub fn repo_root() -> PathBuf {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_nextsync_config(path: PathBuf) -> bool {
|
|
||||||
path.ends_with(".nextsync") || path.starts_with(".nextsync")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn nextsync() -> PathBuf {
|
pub fn nextsync() -> PathBuf {
|
||||||
let mut path = repo_root();
|
let mut path = repo_root();
|
||||||
path.push(".nextsync");
|
path.push(".nextsync");
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
source ./utils.sh
|
|
||||||
|
|
||||||
nb_tests=0
|
|
||||||
TEST_SUITE_NAME="add/directory/"
|
|
||||||
|
|
||||||
add_test_no_env() {
|
|
||||||
touch $2
|
|
||||||
$exe add $3
|
|
||||||
status_cmp "$1" "$4"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_test() {
|
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
|
||||||
$exe init
|
|
||||||
add_test_no_env "$1" "$2" "$3" "$4"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_dir() {
|
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
|
||||||
$exe init
|
|
||||||
mkdir dir
|
|
||||||
$exe add "dir"
|
|
||||||
res=$($exe status --nostyle)
|
|
||||||
status_cmp "dir" "new: dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_subdir() {
|
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
|
||||||
$exe init
|
|
||||||
mkdir foo foo/bar
|
|
||||||
$exe add "foo"
|
|
||||||
res=$($exe status --nostyle)
|
|
||||||
status_cmp "dir" "new: foo/bar\nnew: foo"
|
|
||||||
}
|
|
||||||
|
|
||||||
add_dir
|
|
||||||
add_subdir
|
|
||||||
|
|
||||||
echo $nb_tests
|
|
||||||
exit 0
|
|
@ -1,14 +1,38 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
source ./utils.sh
|
|
||||||
|
|
||||||
nb_tests=0
|
nb_tests=0
|
||||||
TEST_SUITE_NAME="add/file/"
|
TEST_SUITE_NAME="add/file/"
|
||||||
|
|
||||||
|
get_exe() {
|
||||||
|
exe=$(pwd)
|
||||||
|
exe+="/../target/debug/nextsync"
|
||||||
|
if [ ! -f $exe ]; then
|
||||||
|
echo "No executable found, try to compile first" >&2
|
||||||
|
exit 4
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
setup_env() {
|
||||||
|
[ ! -v exe ] && get_exe
|
||||||
|
path=$(mktemp -d)
|
||||||
|
cd $path
|
||||||
|
}
|
||||||
|
|
||||||
|
add_cmp() {
|
||||||
|
res=$($exe status --nostyle)
|
||||||
|
diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo -e "$TEST_SUITE_NAME$1: Output differ:" >&2
|
||||||
|
diff -u <(echo -e "$2" ) <(echo -e "$res") | grep "^[-\+\ ][^-\+]" >&2
|
||||||
|
echo -e "\nMore in $path" >&2
|
||||||
|
echo $nb_tests
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
add_test_no_env() {
|
add_test_no_env() {
|
||||||
touch $2
|
touch $2
|
||||||
$exe add $3
|
$exe add $3
|
||||||
status_cmp "$1" "$4"
|
add_cmp "$1" "$4"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_test() {
|
add_test() {
|
||||||
@ -29,7 +53,7 @@ add_space() {
|
|||||||
touch 'to to'
|
touch 'to to'
|
||||||
$exe add 'to to'
|
$exe add 'to to'
|
||||||
res=$($exe status --nostyle)
|
res=$($exe status --nostyle)
|
||||||
status_cmp "space" "new: to to"
|
add_cmp "space" "new: to to"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_multiple() {
|
add_multiple() {
|
||||||
@ -40,7 +64,7 @@ add_regex() {
|
|||||||
add_test "regex" "titi riri" "./*" "new: riri\nnew: titi"
|
add_test "regex" "titi riri" "./*" "new: riri\nnew: titi"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_file_subdir() {
|
add_subdir() {
|
||||||
nb_tests=$((nb_tests + 1))
|
nb_tests=$((nb_tests + 1))
|
||||||
setup_env
|
setup_env
|
||||||
$exe init
|
$exe init
|
||||||
@ -48,19 +72,7 @@ add_file_subdir() {
|
|||||||
touch dir/toto
|
touch dir/toto
|
||||||
$exe add "./dir/toto"
|
$exe add "./dir/toto"
|
||||||
res=$($exe status --nostyle)
|
res=$($exe status --nostyle)
|
||||||
status_cmp "file_subdir" "new: dir/toto"
|
add_cmp "subdir" "new: dir/toto"
|
||||||
}
|
|
||||||
|
|
||||||
add_whole_subdir() {
|
|
||||||
nb_tests=$((nb_tests + 1))
|
|
||||||
setup_env
|
|
||||||
$exe init
|
|
||||||
mkdir dir
|
|
||||||
touch dir/toto
|
|
||||||
touch dir/roro
|
|
||||||
$exe add "dir"
|
|
||||||
res=$($exe status --nostyle)
|
|
||||||
status_cmp "whole_subdir" "new: dir/roro\nnew: dir/toto\nnew: dir"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
add_subdir_regex() {
|
add_subdir_regex() {
|
||||||
@ -71,7 +83,7 @@ add_subdir_regex() {
|
|||||||
touch dir/toto dir/roro
|
touch dir/toto dir/roro
|
||||||
$exe add "./dir/*"
|
$exe add "./dir/*"
|
||||||
res=$($exe status --nostyle)
|
res=$($exe status --nostyle)
|
||||||
status_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto"
|
add_cmp "subdir_regex" "new: dir/roro\nnew: dir/toto"
|
||||||
}
|
}
|
||||||
|
|
||||||
add_duplication() {
|
add_duplication() {
|
||||||
@ -94,17 +106,20 @@ add_all() {
|
|||||||
touch dir/toto dir/roro lolo
|
touch dir/toto dir/roro lolo
|
||||||
$exe add -A
|
$exe add -A
|
||||||
res=$($exe status --nostyle)
|
res=$($exe status --nostyle)
|
||||||
status_cmp "all" "new: .nextsyncignore\nnew: dir/roro\nnew: dir/toto\nnew: dir\nnew: lolo"
|
add/file/all: Output differ:
|
||||||
|
add_cmp "all" "new: dir/roro\nnew: dir/toto\nnew: lolo\nnew: .nextsyncignore"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#test nextsyncignore
|
||||||
|
#test inside folder
|
||||||
|
#test -A duplication
|
||||||
#test add file without changes
|
#test add file without changes
|
||||||
|
|
||||||
add_basics
|
add_basics
|
||||||
add_space
|
add_space
|
||||||
add_multiple
|
add_multiple
|
||||||
add_regex
|
add_regex
|
||||||
add_file_subdir
|
add_subdir
|
||||||
add_whole_subdir
|
|
||||||
add_subdir_regex
|
add_subdir_regex
|
||||||
add_duplication
|
add_duplication
|
||||||
add_duplication_subdir
|
add_duplication_subdir
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
source ./utils.sh
|
|
||||||
|
|
||||||
# Getting all tests
|
# Getting all tests
|
||||||
TESTS=$(find -mindepth 2 -name "*.sh")
|
TESTS=$(find -name "*.sh" -not -name "main.sh")
|
||||||
if [ $# -ne 0 ]; then
|
if [ $# -ne 0 ]; then
|
||||||
TESTS=$(find -mindepth 2 -path "*$1*")
|
TESTS=$(find -name "*$1*" -not -name "main.sh")
|
||||||
|
tests=""
|
||||||
|
for obj in $TESTS; do
|
||||||
|
[ -d $obj ] && tests+=$(find -path "$obj/*.sh" -not -name "main.sh")
|
||||||
|
done;
|
||||||
|
TESTS=$tests
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Executing tests
|
# Executing tests
|
||||||
@ -15,7 +18,7 @@ for test in $TESTS; do
|
|||||||
#nb_tests=$((nb_tests + 1))
|
#nb_tests=$((nb_tests + 1))
|
||||||
|
|
||||||
# run file
|
# run file
|
||||||
tmp_stderr=$(mktf)
|
tmp_stderr=$(mktemp)
|
||||||
nb_tests_tmp=$($test 2>"$tmp_stderr")
|
nb_tests_tmp=$($test 2>"$tmp_stderr")
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
capture_stderr=$(<"$tmp_stderr")
|
capture_stderr=$(<"$tmp_stderr")
|
||||||
@ -27,10 +30,8 @@ for test in $TESTS; do
|
|||||||
[ $nb_tests_tmp -gt 0 ] &&
|
[ $nb_tests_tmp -gt 0 ] &&
|
||||||
nb_tests=$((nb_tests + nb_tests_tmp))
|
nb_tests=$((nb_tests + nb_tests_tmp))
|
||||||
|
|
||||||
# deal with the result of the test
|
|
||||||
if [ $exit_code -eq 0 ]; then
|
if [ $exit_code -eq 0 ]; then
|
||||||
nb_success=$((nb_success + nb_tests_tmp))
|
nb_success=$((nb_success + nb_tests_tmp))
|
||||||
echo "$test ran successfully"
|
|
||||||
elif [ $exit_code -eq 4 ]; then
|
elif [ $exit_code -eq 4 ]; then
|
||||||
# not executable (nextsync) found, not need to try other tests
|
# not executable (nextsync) found, not need to try other tests
|
||||||
exit 1
|
exit 1
|
||||||
@ -40,6 +41,4 @@ for test in $TESTS; do
|
|||||||
fi
|
fi
|
||||||
done;
|
done;
|
||||||
|
|
||||||
rm -rf /tmp/*_nextsync
|
|
||||||
|
|
||||||
echo -e "\nRan $nb_tests tests ($((nb_tests - nb_success)) Failed)"
|
echo -e "\nRan $nb_tests tests ($((nb_tests - nb_success)) Failed)"
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
mktd()
|
|
||||||
{
|
|
||||||
echo $(mktemp -d --suffix=_nextsync)
|
|
||||||
}
|
|
||||||
|
|
||||||
mktf()
|
|
||||||
{
|
|
||||||
echo $(mktemp --suffix=_nextsync)
|
|
||||||
}
|
|
||||||
|
|
||||||
get_exe() {
|
|
||||||
exe=$(pwd)
|
|
||||||
exe+="/../target/debug/nextsync"
|
|
||||||
if [ ! -f $exe ]; then
|
|
||||||
echo "No executable found, try to compile first" >&2
|
|
||||||
exit 4
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
setup_env() {
|
|
||||||
[ ! -v exe ] && get_exe
|
|
||||||
path=$(mktd)
|
|
||||||
cd $path
|
|
||||||
}
|
|
||||||
|
|
||||||
# test_name expected_output
|
|
||||||
status_cmp() {
|
|
||||||
res=$($exe status --nostyle)
|
|
||||||
diff <(echo -e "$2" ) <(echo -e "$res") 2> /dev/null > /dev/null
|
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo -e "$TEST_SUITE_NAME$1: Output differ:" >&2
|
|
||||||
diff -u <(echo -e "$2" ) <(echo -e "$res") | grep "^[-\+\ ][^-\+]" >&2
|
|
||||||
echo -e "\nMore in $path" >&2
|
|
||||||
echo $nb_tests
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user