Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
526 changes: 526 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ version = "0.1.0"
edition = "2024"

[dependencies]
chrono = "0.4.42"
clap = { version = "4.5.37", features = ["derive"] }
colored = "3.0.0"
directories = "6.0.0"
futures = "0.3.31"
notify = "8.0.0"
serde = { version = "1.0.219", features = ["derive"] }
shellexpand = "3.1.1"
tokio = { version = "1.47.1", features = ["full"] }
tokio-util = { version = "0.7.16", features = ["rt"] }
toml = "0.8.22"

[profile.release]
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ source = '~/projects/my-project/'
destinations = ['username@remote-server:~/my-project']

sync_on_start = true
options = '-az -e ssh --delete'
options = '--delete'

ignore = '''
.git
Expand All @@ -93,14 +93,15 @@ target
#### Global Options

* `debounce`: Debounce interval in seconds for file watching. Prevents excessive syncing during rapid file changes.
* `verbose`: Enables additional logging; can be overridden via command-line option.

#### Per-Sync Job Fields

* `name` (string): Unique name for the sync job.
* `source` (string): Source directory. `~` is expanded to home.
* `destinations` (array of strings): List of destination paths. Can be local or remote via SSH.
* `sync_on_start` (boolean):: If `true`, will sync automatically when the tool starts.
* `options` (string, optional): Optional `rsync` options to override the default (`-az -e ssh`).
* `options` (string, optional): Optional `rsync` options to be specified after the default (`-az -e ssh`).

* **Note**: If `options` is not specified, it defaults to `-az -e ssh`.
* Including `--delete` in the options will cause files in the destination that are not present in the source to be removed. **Use with caution!**
Expand Down
44 changes: 31 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::{fs, path::Path};
use std::{
fs,
path::{Path, PathBuf},
};

use serde::Deserialize;

Expand All @@ -7,11 +10,17 @@ pub struct Config {
#[serde(default = "default_debounce")]
pub debounce: f32,

pub sync: Vec<SyncRule>,
#[serde(default)] // missing field → false
pub verbose: bool,

pub sync: Vec<SyncRuleToml>,

#[serde(skip)]
pub config_path: PathBuf,
}

#[derive(Debug, Deserialize)]
pub struct SyncRule {
pub struct SyncRuleToml {
pub name: String,
pub source: String,
pub destinations: Vec<String>,
Expand All @@ -22,29 +31,38 @@ pub struct SyncRule {
#[serde(default = "default_ignore")]
pub ignore: String,

#[serde(default = "default_options")]
#[serde(default)]
pub options: String,
}

fn default_sync_on_start() -> bool {
true
false
}

fn default_ignore() -> String {
".git\n".into()
}

fn default_options() -> String {
"-az -e ssh".into()
}
// fn default_options() -> String {
// "-az -e ssh".into()
// }

fn default_debounce() -> f32 {
0.08
}

pub fn read_config(path: &Path) -> Config {
let toml_str = fs::read_to_string(path).unwrap_or_else(|e| panic!("Error: failed to read config file: {} {e}", path.display()));
let config: Config = toml::from_str(&toml_str).expect("Failed to parse TOML");
//println!("Parsed config: {:#?}", config);
config
impl Config {
pub fn from_config_path(path: &Path) -> Self {
let toml_str = fs::read_to_string(path).unwrap_or_else(|e| panic!("Error: failed to read config file: {} {e}", path.display()));
let mut config: Config = toml::from_str(&toml_str).expect("Failed to parse TOML");
//println!("Parsed config: {:#?}", config);

config.config_path = path.into();
config
}
pub fn retain_destinations(&mut self, filter: &str) {
for s in self.sync.iter_mut() {
s.destinations.retain(|dest| dest.contains(filter));
}
}
}
28 changes: 22 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::path::PathBuf;

use clap::Parser as clap_Parser;
use clap::Parser;

use crate::config::Config;

mod config;
mod sync;
mod sync_item;
mod sync_manager;

#[derive(clap_Parser, Debug)]
#[derive(Parser, Debug)]
#[command(author, version, about)]
struct Args {
/// Activate debug mode
Expand All @@ -24,9 +27,22 @@ struct Args {
config: PathBuf,
}

fn main() {
#[tokio::main]
async fn main() {
let args = Args::parse();

let config_path = args.config;
sync::run(&config_path, args.filter);
loop {
let mut config = Config::from_config_path(&args.config);

if let Some(filter) = &args.filter {
config.retain_destinations(filter);
}

config.verbose = args.verbose;
// if let Some(verbose) = args.verbose {
// config.verbose = verbose;
// }

sync_manager::sync_projects(config).await;
}
}
232 changes: 0 additions & 232 deletions src/sync.rs

This file was deleted.

Loading