Skip to content

Commit

Permalink
make hooks messages configurable
Browse files Browse the repository at this point in the history
...and update them to reflect current usage

why:
- these messages appeared to be just wrong (referencing `aide` instead of firstaide or an `update` command that doesn't appear to exist)
- and in any case it's nice to have them all customizeable not just the getting_started message. based on the presence of the `Messages` struct I presume this was always intended

how:
- add fields to `Messages` struct, named based on the hook they are associated with
- set sensible defaults for messages
- use serde default attributes to allow mixing defaults and custom messages without errors
- add messages to the hooks scripts
- splat configured messages into hooks scripts based on how it was done for the getting_started message

docs: updated the readme to document messages configuration

validation: tested new message configurations in a different project, `cargo test`
  • Loading branch information
zach-sherman committed Oct 25, 2023
1 parent cca838c commit ea6116d
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,33 @@ impl AsRef<Path> for ParentDir {

#[derive(Debug, Deserialize)]
pub struct Messages {
#[serde(default = "default_getting_started")]
pub getting_started: String,
#[serde(default = "default_stale")]
pub stale: String,
#[serde(default = "default_inactive")]
pub inactive: String,
}

impl Default for Messages {
fn default() -> Self {
Self {
getting_started: "firstaide --help".into(),
stale: "firstaide build".into(),
inactive: "build firstaide and run \"firstaide build\"".into(),
getting_started: default_getting_started(),
stale: default_stale(),
inactive: default_inactive(),
}
}
}

fn default_getting_started() -> String {
"firstaide --help".to_string()
}
fn default_stale() -> String {
"firstaide build".to_string()
}
fn default_inactive() -> String {
"build firstaide and run \"firstaide build\"".to_string()
}

impl Config {
pub fn load<T: Into<PathBuf>>(dir: Option<T>) -> Result<Config> {
let dir = match dir {
Expand Down

0 comments on commit ea6116d

Please sign in to comment.