Skip to content

Commit

Permalink
Merge pull request #19 from rafaeldelboni/feat/add-verbose-mode
Browse files Browse the repository at this point in the history
feat: Adds verbose mode
  • Loading branch information
rafaeldelboni authored Sep 4, 2022
2 parents ba4d4c3 + 2888fb9 commit 42b8c5c
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 3 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Tool for managing dotfiles directories; Heavily based on [rcm](http://thoughtbot
- [x] Option to always override (-f --force)
- [x] Add version command (-V --version)
- [x] Add dry-run command (-D --dry-run)
- [ ] Add verbosity command (-v)
- [x] Add verbosity command (-v --verbose)
- [ ] Add drop/delete command, this deletes dotfiles managed by paro (-d --down)
- CI Pipeline to build releases
- [ ] Linux (x86_64)
Expand Down Expand Up @@ -90,6 +90,9 @@ Do not install files that match <file-pattern>. Tagged files go in a directory n
the tag, prefixed with tag-. Therefore, files under .dotfiles/tag-git are only installed
when installing using the git tag. This can be repeated with additional patterns.

#### -v, --verbose
Make the operation more talkative. This can be repeated for more verbosity.

#### -V, --version
Print version information

Expand Down
5 changes: 3 additions & 2 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ impl Actions {
}

fn log(&mut self, level: Log, message: String) {
// TODO replace 4 with verbosity settings in clap
if (level as u16 <= 4) || self.file_actions.settings.dry_run {
if (level as u8 <= self.file_actions.settings.verbose)
|| self.file_actions.settings.dry_run
{
self.stdio.writeln(message);
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/parsers/clap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ impl ClapParser {
A simulated or practice performance; rehearsal.",
)
.action(ArgAction::SetTrue),
)
.arg(
Arg::new("verbose")
.short('v')
.long("verbose")
.help("Make the operation more talkative")
.long_help(
"Make the operation more talkative. \
This can be repeated for more verbosity.",
)
.action(ArgAction::Count),
);

Self { clap: app }
Expand All @@ -164,6 +175,7 @@ impl ClapParser {
force: matches.get_one::<bool>("force").copied().unwrap(),
down: matches.get_one::<bool>("down").copied().unwrap(),
dry_run: matches.get_one::<bool>("dry-run").copied().unwrap(),
verbose: matches.get_one::<u8>("verbose").copied().unwrap(),
}
}
}
Expand Down Expand Up @@ -210,6 +222,7 @@ mod tests {
assert_eq!(settings.force, false);
assert_eq!(settings.down, false);
assert_eq!(settings.dry_run, false);
assert_eq!(settings.verbose, 0);
}

#[test]
Expand Down Expand Up @@ -278,4 +291,10 @@ mod tests {
]);
assert_eq!(settings.destination, "/new/home2");
}

#[test]
fn test_clap_verbose() {
let settings = ClapParser::new().into_settings(vec!["paro", "-vv"]);
assert_eq!(settings.verbose, 2);
}
}
9 changes: 9 additions & 0 deletions src/parsers/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ impl ConfigParser {
.unwrap()
.set_default("dry-run", false)
.unwrap()
.set_default("verbose", 0)
.unwrap()
.build()
.unwrap(),
}
Expand Down Expand Up @@ -66,6 +68,7 @@ mod tests {
assert_eq!(settings.force, false);
assert_eq!(settings.down, false);
assert_eq!(settings.dry_run, false);
assert_eq!(settings.verbose, 0);
}

#[test]
Expand Down Expand Up @@ -121,4 +124,10 @@ mod tests {
let settings = ConfigParser::new(&config_file()).into_settings();
assert_eq!(settings.dry_run, true);
}

#[test]
fn test_config_verbose() {
let settings = ConfigParser::new(&config_file()).into_settings();
assert_eq!(settings.verbose, 2);
}
}
10 changes: 10 additions & 0 deletions src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct Settings {
pub force: bool,
pub down: bool,
pub dry_run: bool,
pub verbose: u8,
}

impl Settings {
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Settings {
force: self.force,
down: self.down,
dry_run: self.dry_run,
verbose: self.verbose,
}
}

Expand Down Expand Up @@ -99,6 +101,7 @@ impl Settings {
force: self.force || other.force,
down: self.down || other.down,
dry_run: self.dry_run || other.dry_run,
verbose: self.verbose | other.verbose,
}
}

Expand Down Expand Up @@ -130,6 +133,7 @@ impl Default for Settings {
force: false,
down: false,
dry_run: false,
verbose: 0,
}
}
}
Expand All @@ -154,6 +158,7 @@ mod tests {
force: true,
down: true,
dry_run: true,
verbose: 2,
};

let settings_with_defaults = settings_1.clone().with_defaults();
Expand All @@ -166,6 +171,7 @@ mod tests {
assert_eq!(settings_with_defaults.force, settings_1.force);
assert_eq!(settings_with_defaults.down, settings_1.down);
assert_eq!(settings_with_defaults.dry_run, settings_1.dry_run);
assert_eq!(settings_with_defaults.verbose, settings_1.verbose);
}

#[test]
Expand All @@ -181,6 +187,7 @@ mod tests {
force: true,
down: true,
dry_run: true,
verbose: 2,
};
let settings_2 = Settings {
tags: to_string_vec(vec!["t2", "t2"]),
Expand All @@ -192,6 +199,7 @@ mod tests {
force: false,
down: false,
dry_run: false,
verbose: 0,
};

let merged_settings = settings_empty.merge(settings_1.clone());
Expand All @@ -204,6 +212,7 @@ mod tests {
assert_eq!(merged_settings.force, settings_1.force);
assert_eq!(merged_settings.down, settings_1.down);
assert_eq!(merged_settings.dry_run, settings_1.dry_run);
assert_eq!(merged_settings.verbose, settings_1.verbose);

let merged2_settings = settings_1.clone().merge(settings_2.clone());
assert_eq!(
Expand All @@ -227,6 +236,7 @@ mod tests {
assert_eq!(merged2_settings.force, settings_1.force);
assert_eq!(merged2_settings.down, settings_1.down);
assert_eq!(merged2_settings.dry_run, settings_1.dry_run);
assert_eq!(merged2_settings.verbose, settings_1.verbose);
}

#[test]
Expand Down
1 change: 1 addition & 0 deletions tests/settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ hostname="hostname-in-config"
force=true
down=true
dry-run=true
verbose=2

0 comments on commit 42b8c5c

Please sign in to comment.