Compare commits

...

5 Commits

Author SHA1 Message Date
Bauke 06899c42c7
Add an explicit --config to the default hook template. 2022-11-01 13:42:14 +01:00
Bauke 4dab507636
Add config file configuration. 2022-11-01 13:38:52 +01:00
Bauke b386e59c3e
Start using Hooked! 2022-11-01 12:27:55 +01:00
Bauke ac1fb0163c
1 is singular, not 0. 🤦 2022-11-01 12:27:01 +01:00
Bauke d4f22fb0c5
Pluralize words correctly. 2022-10-31 22:05:47 +01:00
9 changed files with 36 additions and 6 deletions

3
Hooked.toml Normal file
View File

@ -0,0 +1,3 @@
[[pre_commit]]
name = "Cargo Complete Check"
command = "cargo make complete-check"

View File

@ -10,6 +10,8 @@ use {
supports_color::Stream,
};
use crate::utilities::plural;
/// The `run` subcommand.
pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
let (success_style, warn_style, error_style) =
@ -25,9 +27,11 @@ pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
};
if hook_type == "pre-commit" {
let hook_count = config.pre_commit.len();
println!(
"Hooked: Running {} pre-commit hooks.",
config.pre_commit.len()
"Hooked: Running {} pre-commit {}.",
hook_count,
plural(hook_count, "hook", None)
);
for hook in config.pre_commit {

View File

@ -27,6 +27,7 @@ pub const DEFAULT_TEMPLATE: &str = include_str!("templates/default.sh");
pub const HOOK_TYPES: [&str; 1] = ["pre-commit"];
mod cli;
mod utilities;
fn main() -> Result<()> {
install()?;
@ -44,6 +45,7 @@ fn main() -> Result<()> {
for hook_type in HOOK_TYPES {
let mut context = Context::new();
context.insert("config_path", &config.general.config);
context.insert("hook_type", hook_type);
let hook_path = git_hooks_dir.join(hook_type);

View File

@ -2,4 +2,4 @@
# Installed by Hooked.
hooked run {{ hook_type }}
hooked run {{ hook_type }} --config {{ config_path }}

View File

@ -0,0 +1,14 @@
//! Miscellaneous utilities.
/// Simple function to create a pluralized string.
pub fn plural(count: usize, singular: &str, plural: Option<&str>) -> String {
if count == 1 {
return singular.to_string();
}
if let Some(plural) = plural {
return plural.to_string();
}
format!("{singular}s")
}

View File

@ -8,6 +8,9 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
#[serde(default, deny_unknown_fields)]
pub struct General {
/// Path to the Hooked configuration file.
pub config: PathBuf,
/// The directory to use for hooks.
pub directory: PathBuf,
}
@ -15,6 +18,7 @@ pub struct General {
impl Default for General {
fn default() -> Self {
Self {
config: PathBuf::from("Hooked.toml"),
directory: PathBuf::from("hooks"),
}
}

View File

@ -1,9 +1,10 @@
---
source: tests/parsing.rs
source: hooked-config/tests/parsing.rs
expression: config
---
Config {
general: General {
config: "Hooked.toml",
directory: "hooks",
},
pre_commit: [

View File

@ -1,9 +1,10 @@
---
source: tests/parsing.rs
source: hooked-config/tests/parsing.rs
expression: config
---
Config {
general: General {
config: "Hooked.toml",
directory: "hooked",
},
pre_commit: [

View File

@ -1,8 +1,9 @@
---
source: tests/serialize.rs
source: hooked-config/tests/serialize.rs
expression: to_string_pretty(&config).unwrap()
---
[general]
config = 'Hooked.toml'
directory = 'hooks'
[[pre_commit]]