Compare commits
5 Commits
4f28ced1b1
...
06899c42c7
Author | SHA1 | Date |
---|---|---|
Bauke | 06899c42c7 | |
Bauke | 4dab507636 | |
Bauke | b386e59c3e | |
Bauke | ac1fb0163c | |
Bauke | d4f22fb0c5 |
|
@ -0,0 +1,3 @@
|
|||
[[pre_commit]]
|
||||
name = "Cargo Complete Check"
|
||||
command = "cargo make complete-check"
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
# Installed by Hooked.
|
||||
|
||||
hooked run {{ hook_type }}
|
||||
hooked run {{ hook_type }} --config {{ config_path }}
|
||||
|
|
|
@ -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")
|
||||
}
|
|
@ -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"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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: [
|
||||
|
|
|
@ -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]]
|
||||
|
|
Loading…
Reference in New Issue