-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add init subcommand * chore: update sample config * doc: add doc page for init subcommand * fix: also create uuid file during init * style: run cargo fmt * style: make clippy happy * test: fix failing test * doc: add hoard init to list of commands * chore: resolve clippy error
- Loading branch information
Showing
12 changed files
with
186 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Initial Setup | ||
|
||
Hoard v0.5.2 added the `init` subcommand to create the folders and files necessary for Hoard to run. | ||
|
||
> This command only needs to be run the first time you set Hoard up. After that, including on new | ||
> machines, it is enough to synchronize the [hoard data directory][hoard-data-dir] to the new | ||
> machine and setup or restore the [configuration file][hoard-config-file]. | ||
## Initializing Hoard | ||
|
||
Run `hoard init`. Everything necessary will be created, including a sample configuration file. | ||
|
||
Then, run `hoard edit` to [edit the new configuration file][edit-config-file]. | ||
|
||
[hoard-data-dir]: ../file-locations.md#hoard-data-directroy | ||
[hoard-config-file]: ../file-locations.md#config-file | ||
[edit-config-file]: ./create-config/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
use crate::checkers::history::{get_or_generate_uuid, get_uuid_file}; | ||
use crate::Config; | ||
use tokio::fs; | ||
|
||
use super::DEFAULT_CONFIG; | ||
|
||
#[tracing::instrument(skip_all)] | ||
pub(crate) async fn run_init(config: &Config) -> Result<(), super::Error> { | ||
let data_dir = crate::paths::hoards_dir(); | ||
let config_file = config.config_file.as_path(); | ||
|
||
tracing::info!("creating data directory: {}", data_dir.display()); | ||
fs::create_dir_all(&data_dir) | ||
.await | ||
.map_err(|error| super::Error::Init { | ||
path: data_dir.to_path_buf(), | ||
error, | ||
})?; | ||
|
||
if let Some(parent) = config_file.parent() { | ||
tracing::info!("creating config directory: {}", parent.display()); | ||
fs::create_dir_all(parent) | ||
.await | ||
.map_err(|error| super::Error::Init { | ||
path: parent.to_path_buf(), | ||
error, | ||
})?; | ||
} | ||
|
||
let uuid_file = get_uuid_file(); | ||
if !uuid_file.exists() { | ||
tracing::info!("device id not found, creating a new one"); | ||
get_or_generate_uuid() | ||
.await | ||
.map_err(|error| super::Error::Init { | ||
path: uuid_file, | ||
error, | ||
})?; | ||
} | ||
|
||
if !config_file.exists() { | ||
tracing::info!( | ||
"no configuration file found, creating default at {}", | ||
config_file.display() | ||
); | ||
fs::write(config_file, DEFAULT_CONFIG) | ||
.await | ||
.map_err(|error| super::Error::Init { | ||
path: config_file.to_path_buf(), | ||
error, | ||
})?; | ||
} | ||
|
||
tracing::info!( | ||
"If you want to synchronize hoards between multiple machines, synchronize {}", | ||
data_dir.display() | ||
); | ||
tracing::info!("To synchronize your Hoard configuration as well, add an entry that backs up {}, not the whole directory", config_file.display()); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
mod common; | ||
|
||
use common::tester::Tester; | ||
use hoard::command::Command; | ||
use tokio::fs; | ||
|
||
#[tokio::test] | ||
async fn test_hoard_init() { | ||
let tester = Tester::new("").await; | ||
|
||
fs::remove_dir(tester.config_dir()) | ||
.await | ||
.expect("should have deleted hoard config dir"); | ||
if tester.data_dir().exists() { | ||
// config dir and data dir are the same on macos | ||
fs::remove_dir(tester.data_dir()) | ||
.await | ||
.expect("should have deleted hoard data dir"); | ||
} | ||
|
||
assert!( | ||
!tester.config_dir().exists(), | ||
"hoard config directory should not exist" | ||
); | ||
assert!( | ||
!tester.data_dir().exists(), | ||
"hoard data directory should not exist" | ||
); | ||
|
||
tester | ||
.run_command(Command::Init) | ||
.await | ||
.expect("initialization should succeed"); | ||
|
||
assert!( | ||
tester.config_dir().exists(), | ||
"hoard config directory should exist" | ||
); | ||
assert!( | ||
tester.data_dir().exists(), | ||
"hoard data directory should exist" | ||
); | ||
|
||
let config_file = tester.config_dir().join("config.toml"); | ||
|
||
assert!(config_file.exists(), "config file should have been created"); | ||
} |