Skip to content

Commit ede6828

Browse files
committed
docs: document public functions
1 parent 98afb6c commit ede6828

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

src/dots.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl Dot {
6060
let mut vars = vars.clone();
6161

6262
if let Some(local_vars_path) = self.resolve_var_path(dotfile_dir) {
63-
let local_vars = Dot::get_local_vars(&local_vars_path, gpg);
63+
let local_vars = Dot::load_local_vars(&local_vars_path, gpg);
6464
vars.extend(local_vars);
6565
}
6666

@@ -112,7 +112,7 @@ impl Dot {
112112
}
113113
}
114114

115-
fn get_local_vars(source: &Path, gpg: Option<&Gpg>) -> Variables {
115+
fn load_local_vars(source: &Path, gpg: Option<&Gpg>) -> Variables {
116116
Variables::from_toml(source, gpg).unwrap_or_else(|err| {
117117
eprintln!("{}", err.to_string().yellow());
118118
Variables::default()

src/gpg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Gpg {
1313
}
1414

1515
impl Gpg {
16-
pub fn new(user_id: &str) -> Self {
16+
pub(crate) fn new(user_id: &str) -> Self {
1717
Gpg {
1818
user_id: user_id.to_string(),
1919
}

src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ pub mod settings;
2626
mod state;
2727
mod templating;
2828

29-
pub const BOMBADIL_CONFIG: &str = "bombadil.toml";
29+
pub(crate) const BOMBADIL_CONFIG: &str = "bombadil.toml";
3030

31+
/// The main crate struct, it contains all needed medata about a
32+
/// dotfile directory and how to install it.
3133
pub struct Bombadil {
3234
path: PathBuf,
3335
dots: HashMap<String, Dot>,
@@ -38,12 +40,16 @@ pub struct Bombadil {
3840
gpg: Option<Gpg>,
3941
}
4042

43+
/// Enable or disable GPG encryption when linking dotfiles
4144
pub enum Mode {
4245
Gpg,
4346
NoGpg,
4447
}
4548

4649
impl Bombadil {
50+
/// Given a git remote address, will clone the repository to the target path
51+
/// and install the dotfiles according to the "bombadil.toml" configuration inside the
52+
/// repo root.
4753
pub fn install_from_remote(
4854
remote: &str,
4955
path: PathBuf,
@@ -63,6 +69,7 @@ impl Bombadil {
6369
Ok(())
6470
}
6571

72+
/// Symlink `bombadil.toml` to `$XDG_CONFIG/bombadil.toml` so we can later read it from there.
6673
pub fn link_self_config(dotfiles_path: Option<PathBuf>) -> Result<()> {
6774
let xdg_config_dir = dirs::config_dir();
6875
if xdg_config_dir.is_none() {
@@ -101,6 +108,13 @@ impl Bombadil {
101108
})
102109
}
103110

111+
/// The installation process is composed of the following steps :
112+
/// 1. Run pre install hooks
113+
/// 2. If any previous state is found in `.dot/previous_state.toml`, remove the existing symlinks
114+
/// 3. Clean existing rendered dotfiles templates in `.dot`
115+
/// 4. Copy and symlink dotfiles according to the current `$XDG_CONFIG/bombadil.toml` configuration
116+
/// 5. Run post install hooks
117+
/// 6. Write current state to `.dot/previous_state.toml`
104118
pub fn install(&self) -> Result<()> {
105119
self.check_dotfile_dir()?;
106120
self.prehooks.iter().map(Hook::run).for_each(|result| {
@@ -161,6 +175,7 @@ impl Bombadil {
161175
Ok(())
162176
}
163177

178+
/// Unlink dotfiles according to previous state
164179
pub fn uninstall(&self) -> Result<()> {
165180
let mut success_paths: Vec<&PathBuf> = Vec::new();
166181
let mut error_paths: Vec<&anyhow::Error> = Vec::new();
@@ -196,6 +211,7 @@ impl Bombadil {
196211
Ok(())
197212
}
198213

214+
/// Add a gpg secret encrypted variable to the target variable file
199215
pub fn add_secret<S: AsRef<Path> + ?Sized>(
200216
&self,
201217
key: &str,
@@ -209,13 +225,15 @@ impl Bombadil {
209225
}
210226
}
211227

228+
/// Pretty print current bombadil variables
212229
pub fn display_vars(&self) {
213230
self.vars
214231
.variables
215232
.iter()
216233
.for_each(|(key, value)| println!("{} = {}", key.red(), value))
217234
}
218235

236+
/// Enable a dotfile profile by merging its config with the default profile
219237
pub fn enable_profiles(&mut self, profile_keys: Vec<&str>) -> Result<()> {
220238
let profiles: Vec<Profile> = profile_keys
221239
.iter()
@@ -326,6 +344,7 @@ impl Bombadil {
326344
Ok(())
327345
}
328346

347+
/// Load Bombadil config from a `bombadil.toml`
329348
pub fn from_settings(mode: Mode) -> Result<Bombadil> {
330349
let config = Settings::get()?;
331350
let path = config.get_dotfiles_path()?;
@@ -369,6 +388,7 @@ impl Bombadil {
369388
})
370389
}
371390

391+
/// Pretty print metadata, possible values are Dots, PreHooks, PostHook, Path, Profiles, Vars, Secrets
372392
pub fn print_metadata(&self, metadata_type: MetadataType) {
373393
let rows = match metadata_type {
374394
MetadataType::Dots => self

0 commit comments

Comments
 (0)