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,
|
supports_color::Stream,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use crate::utilities::plural;
|
||||||
|
|
||||||
/// The `run` subcommand.
|
/// The `run` subcommand.
|
||||||
pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
|
pub fn hooked_run(config: Config, hook_type: String) -> Result<()> {
|
||||||
let (success_style, warn_style, error_style) =
|
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" {
|
if hook_type == "pre-commit" {
|
||||||
|
let hook_count = config.pre_commit.len();
|
||||||
println!(
|
println!(
|
||||||
"Hooked: Running {} pre-commit hooks.",
|
"Hooked: Running {} pre-commit {}.",
|
||||||
config.pre_commit.len()
|
hook_count,
|
||||||
|
plural(hook_count, "hook", None)
|
||||||
);
|
);
|
||||||
|
|
||||||
for hook in config.pre_commit {
|
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"];
|
pub const HOOK_TYPES: [&str; 1] = ["pre-commit"];
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
|
mod utilities;
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
install()?;
|
install()?;
|
||||||
|
@ -44,6 +45,7 @@ fn main() -> Result<()> {
|
||||||
|
|
||||||
for hook_type in HOOK_TYPES {
|
for hook_type in HOOK_TYPES {
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
|
context.insert("config_path", &config.general.config);
|
||||||
context.insert("hook_type", hook_type);
|
context.insert("hook_type", hook_type);
|
||||||
|
|
||||||
let hook_path = git_hooks_dir.join(hook_type);
|
let hook_path = git_hooks_dir.join(hook_type);
|
||||||
|
|
|
@ -2,4 +2,4 @@
|
||||||
|
|
||||||
# Installed by Hooked.
|
# 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)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[serde(default, deny_unknown_fields)]
|
#[serde(default, deny_unknown_fields)]
|
||||||
pub struct General {
|
pub struct General {
|
||||||
|
/// Path to the Hooked configuration file.
|
||||||
|
pub config: PathBuf,
|
||||||
|
|
||||||
/// The directory to use for hooks.
|
/// The directory to use for hooks.
|
||||||
pub directory: PathBuf,
|
pub directory: PathBuf,
|
||||||
}
|
}
|
||||||
|
@ -15,6 +18,7 @@ pub struct General {
|
||||||
impl Default for General {
|
impl Default for General {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
config: PathBuf::from("Hooked.toml"),
|
||||||
directory: PathBuf::from("hooks"),
|
directory: PathBuf::from("hooks"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
---
|
---
|
||||||
source: tests/parsing.rs
|
source: hooked-config/tests/parsing.rs
|
||||||
expression: config
|
expression: config
|
||||||
---
|
---
|
||||||
Config {
|
Config {
|
||||||
general: General {
|
general: General {
|
||||||
|
config: "Hooked.toml",
|
||||||
directory: "hooks",
|
directory: "hooks",
|
||||||
},
|
},
|
||||||
pre_commit: [
|
pre_commit: [
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
---
|
---
|
||||||
source: tests/parsing.rs
|
source: hooked-config/tests/parsing.rs
|
||||||
expression: config
|
expression: config
|
||||||
---
|
---
|
||||||
Config {
|
Config {
|
||||||
general: General {
|
general: General {
|
||||||
|
config: "Hooked.toml",
|
||||||
directory: "hooked",
|
directory: "hooked",
|
||||||
},
|
},
|
||||||
pre_commit: [
|
pre_commit: [
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
---
|
---
|
||||||
source: tests/serialize.rs
|
source: hooked-config/tests/serialize.rs
|
||||||
expression: to_string_pretty(&config).unwrap()
|
expression: to_string_pretty(&config).unwrap()
|
||||||
---
|
---
|
||||||
[general]
|
[general]
|
||||||
|
config = 'Hooked.toml'
|
||||||
directory = 'hooks'
|
directory = 'hooks'
|
||||||
|
|
||||||
[[pre_commit]]
|
[[pre_commit]]
|
||||||
|
|
Loading…
Reference in New Issue