@@ -26,8 +26,10 @@ pub mod settings;
2626mod state;
2727mod 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.
3133pub 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
4144pub enum Mode {
4245 Gpg ,
4346 NoGpg ,
4447}
4548
4649impl 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