Drop init subcommand.
parent
7debe754d1
commit
258ac51b51
64
README.md
64
README.md
|
@ -25,45 +25,69 @@ Locations are searched in the following priority:
|
||||||
- `$XDG_CONFIG_HOME/homesync.yml`
|
- `$XDG_CONFIG_HOME/homesync.yml`
|
||||||
- `$XDG_CONFIG_HOME/homesync/homesync.yml`
|
- `$XDG_CONFIG_HOME/homesync/homesync.yml`
|
||||||
|
|
||||||
That said, it is recommended to modify this config solely from the exposed
|
The config file should look like the following:
|
||||||
homesync CLI. Homesync will take responsibility ensuring the generated
|
|
||||||
configuration is according to package manager, platform, etc.
|
```yaml
|
||||||
|
---
|
||||||
|
user:
|
||||||
|
name: jrpotter
|
||||||
|
email: jrpotter@github.io
|
||||||
|
local: $HOME/.homesync
|
||||||
|
remote:
|
||||||
|
name: origin
|
||||||
|
branch: master
|
||||||
|
url: "https://github.com/jrpotter/home-config.git"
|
||||||
|
packages:
|
||||||
|
homesync:
|
||||||
|
configs:
|
||||||
|
- $HOME/.homesync.yml
|
||||||
|
- $HOME/.config/homesync/homesync.yml
|
||||||
|
- $XDG_CONFIG_HOME/homesync.yml
|
||||||
|
- $XDG_CONFIG_HOME/homesync/homesync.yml
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
Copy over [examples/template.yaml](https://github.com/jrpotter/homesync/blob/main/examples/template.yaml)
|
||||||
|
to where you'd like as a starting point.
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Verify your installation by running `homesync` from the command line. If
|
Verify your installation by running `homesync` from the command line. To have
|
||||||
installed, you will likely want to initialize a new config instance. Do so by
|
your local repository match the remote, run
|
||||||
typing:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ homesync init
|
$ homesync pull
|
||||||
```
|
```
|
||||||
|
|
||||||
You can then walk through what github repository you want to sync your various
|
If you make a change to a configuration tracked by homesync, you can tell
|
||||||
files with. You can have homesync automatically monitor all configuration files
|
homesync to prep pushing those changes via the `stage` subcommand or rely on
|
||||||
and post updates on changes by running
|
the daemon service to do it for you:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ homesync daemon
|
$ homesync stage
|
||||||
|
$ homesync daemon &
|
||||||
```
|
```
|
||||||
|
|
||||||
As changes are made to your `homesync` config or any configuration files
|
Homesync will find all tracked files that have changed and stage them in the
|
||||||
referred to within the `homesync` config, the daemon service will sync the
|
local repository. You can then push those changes using
|
||||||
changes to the local git repository. To push these changes upward, run
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ homesync push --all
|
$ homesync push
|
||||||
```
|
```
|
||||||
|
|
||||||
which will expose a git interface for you to complete the push. Lastly, to sync
|
If looking to copy a configuration tracked by homesync to your desktop, you
|
||||||
the remote configurations to your local files, run
|
can run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ homesync pull --all
|
$ homesync apply <filename>
|
||||||
```
|
```
|
||||||
|
|
||||||
This will load up a diff wrapper for you to ensure you make the changes you'd
|
To copy all configurations (and optionally overwrite files that already exist),
|
||||||
like.
|
you can run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ homesync apply --all [--overwrite]
|
||||||
|
```
|
||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
---
|
||||||
|
user:
|
||||||
|
name: name
|
||||||
|
email: email@email.com
|
||||||
|
local: $HOME/.homesync
|
||||||
|
remote:
|
||||||
|
name: origin
|
||||||
|
branch: master
|
||||||
|
url: "https://github.com/owner/repo.git"
|
||||||
|
packages:
|
||||||
|
homesync:
|
||||||
|
configs:
|
||||||
|
- $HOME/.homesync.yml
|
||||||
|
- $HOME/.config/homesync/homesync.yml
|
||||||
|
- $XDG_CONFIG_HOME/homesync.yml
|
||||||
|
- $XDG_CONFIG_HOME/homesync/homesync.yml
|
|
@ -157,7 +157,7 @@ pub fn launch(mut pc: PathConfig, repo: Repository, freq_secs: u64) -> Result<()
|
||||||
let mut state = WatchState::new(poll_tx, &mut watcher)?;
|
let mut state = WatchState::new(poll_tx, &mut watcher)?;
|
||||||
state.update(&pc);
|
state.update(&pc);
|
||||||
loop {
|
loop {
|
||||||
git::apply(&pc, &repo)?;
|
git::stage(&pc, &repo)?;
|
||||||
// Received paths should always be fully resolved.
|
// Received paths should always be fully resolved.
|
||||||
match watch_rx.recv() {
|
match watch_rx.recv() {
|
||||||
Ok(DebouncedEvent::NoticeWrite(p)) => {
|
Ok(DebouncedEvent::NoticeWrite(p)) => {
|
||||||
|
|
|
@ -132,7 +132,7 @@ pub fn init(pc: &PathConfig) -> Result<Repository> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========================================
|
// ========================================
|
||||||
// Application
|
// Staging
|
||||||
// ========================================
|
// ========================================
|
||||||
|
|
||||||
fn find_repo_files(path: &Path) -> Result<Vec<ResPathBuf>> {
|
fn find_repo_files(path: &Path) -> Result<Vec<ResPathBuf>> {
|
||||||
|
@ -166,7 +166,7 @@ fn find_package_files(pc: &PathConfig) -> Vec<ResPathBuf> {
|
||||||
seen
|
seen
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply(pc: &PathConfig, repo: &Repository) -> Result<()> {
|
pub fn stage(pc: &PathConfig, repo: &Repository) -> Result<()> {
|
||||||
let workdir = repo.workdir().ok_or(Error::NotWorkingRepo)?;
|
let workdir = repo.workdir().ok_or(Error::NotWorkingRepo)?;
|
||||||
let repo_files = find_repo_files(&workdir)?;
|
let repo_files = find_repo_files(&workdir)?;
|
||||||
let package_files = find_package_files(&pc);
|
let package_files = find_package_files(&pc);
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -8,12 +8,6 @@ use std::error::Error;
|
||||||
|
|
||||||
type Result = std::result::Result<(), Box<dyn Error>>;
|
type Result = std::result::Result<(), Box<dyn Error>>;
|
||||||
|
|
||||||
pub fn run_apply(config: PathConfig) -> Result {
|
|
||||||
let repo = git::init(&config)?;
|
|
||||||
git::apply(&config, &repo)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn run_daemon(config: PathConfig, freq_secs: u64) -> Result {
|
pub fn run_daemon(config: PathConfig, freq_secs: u64) -> Result {
|
||||||
let repo = git::init(&config)?;
|
let repo = git::init(&config)?;
|
||||||
daemon::launch(config, repo, freq_secs)?;
|
daemon::launch(config, repo, freq_secs)?;
|
||||||
|
@ -30,3 +24,9 @@ pub fn run_push(config: PathConfig) -> Result {
|
||||||
git::push(&config, &mut repo)?;
|
git::push(&config, &mut repo)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn run_stage(config: PathConfig) -> Result {
|
||||||
|
let repo = git::init(&config)?;
|
||||||
|
git::stage(&config, &repo)?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
|
@ -38,9 +38,6 @@ fn main() {
|
||||||
.help("Specify a configuration file to use in place of defaults")
|
.help("Specify a configuration file to use in place of defaults")
|
||||||
.takes_value(true),
|
.takes_value(true),
|
||||||
)
|
)
|
||||||
.subcommand(
|
|
||||||
App::new("apply").about("Find all changes and apply them to the local repository"),
|
|
||||||
)
|
|
||||||
.subcommand(
|
.subcommand(
|
||||||
App::new("daemon")
|
App::new("daemon")
|
||||||
.about("Start up a new homesync daemon")
|
.about("Start up a new homesync daemon")
|
||||||
|
@ -62,6 +59,9 @@ fn main() {
|
||||||
)
|
)
|
||||||
.subcommand(App::new("list").about("See which packages homesync manages"))
|
.subcommand(App::new("list").about("See which packages homesync manages"))
|
||||||
.subcommand(App::new("push").about("Push changes from local to remote"))
|
.subcommand(App::new("push").about("Push changes from local to remote"))
|
||||||
|
.subcommand(
|
||||||
|
App::new("stage").about("Find all changes and stage them onto the local repository"),
|
||||||
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
|
|
||||||
if let Err(e) = dispatch(matches) {
|
if let Err(e) = dispatch(matches) {
|
||||||
|
@ -73,7 +73,6 @@ fn dispatch(matches: clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||||
let candidates = find_candidates(&matches)?;
|
let candidates = find_candidates(&matches)?;
|
||||||
let config = homesync::config::load(&candidates)?;
|
let config = homesync::config::load(&candidates)?;
|
||||||
match matches.subcommand() {
|
match matches.subcommand() {
|
||||||
Some(("apply", _)) => Ok(homesync::run_apply(config)?),
|
|
||||||
Some(("daemon", matches)) => {
|
Some(("daemon", matches)) => {
|
||||||
let freq_secs: u64 = match matches.value_of("frequency") {
|
let freq_secs: u64 = match matches.value_of("frequency") {
|
||||||
Some(f) => f.parse().unwrap_or(0),
|
Some(f) => f.parse().unwrap_or(0),
|
||||||
|
@ -88,6 +87,7 @@ fn dispatch(matches: clap::ArgMatches) -> Result<(), Box<dyn Error>> {
|
||||||
}
|
}
|
||||||
Some(("list", _)) => Ok(homesync::run_list(config)?),
|
Some(("list", _)) => Ok(homesync::run_list(config)?),
|
||||||
Some(("push", _)) => Ok(homesync::run_push(config)?),
|
Some(("push", _)) => Ok(homesync::run_push(config)?),
|
||||||
|
Some(("stage", _)) => Ok(homesync::run_stage(config)?),
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue