Compare commits
7 Commits
0d09e2e086
...
260bcb7ca5
Author | SHA1 | Date |
---|---|---|
Bauke | 260bcb7ca5 | |
Bauke | ba6d4fb0d1 | |
Bauke | d031374360 | |
Bauke | 762051116e | |
Bauke | 15dcca32b0 | |
Bauke | 3da03abe16 | |
Bauke | 6512eaac5a |
|
@ -1,9 +1,5 @@
|
||||||
# Generated by Cargo
|
.direnv/
|
||||||
debug/
|
|
||||||
target/
|
|
||||||
|
|
||||||
# Code coverage results
|
|
||||||
coverage/
|
coverage/
|
||||||
|
debug/
|
||||||
# mdBook output
|
|
||||||
hooked-book/book/
|
hooked-book/book/
|
||||||
|
target/
|
||||||
|
|
|
@ -3,3 +3,11 @@ members = [
|
||||||
"hooked-cli",
|
"hooked-cli",
|
||||||
"hooked-config"
|
"hooked-config"
|
||||||
]
|
]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
|
[workspace.lints.clippy]
|
||||||
|
missing_docs_in_private_items = "warn"
|
||||||
|
|
||||||
|
[workspace.lints.rust]
|
||||||
|
missing_docs = "warn"
|
||||||
|
unsafe_code = "forbid"
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"flake-utils": {
|
||||||
|
"inputs": {
|
||||||
|
"systems": "systems"
|
||||||
|
},
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1705309234,
|
||||||
|
"narHash": "sha256-uNRRNRKmJyCRC/8y1RqBkqWBLM034y4qN7EprSdmgyA=",
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"rev": "1ef2e671c3b0c19053962c07dbda38332dcebf26",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "numtide",
|
||||||
|
"repo": "flake-utils",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1705403940,
|
||||||
|
"narHash": "sha256-bl7E3w35Bleiexg01WsN0RuAQEL23HaQeNBC2zjt+9w=",
|
||||||
|
"owner": "NixOS",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "f0326542989e1bdac955ad6269b334a8da4b0c95",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"systems": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1681028828,
|
||||||
|
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nix-systems",
|
||||||
|
"repo": "default",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
{
|
||||||
|
inputs.flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, flake-utils }:
|
||||||
|
flake-utils.lib.eachDefaultSystem (system:
|
||||||
|
let
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
devShells.default = import ./shell.nix { inherit pkgs; };
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
|
@ -14,6 +14,9 @@ edition = "2021"
|
||||||
name = "hooked"
|
name = "hooked"
|
||||||
path = "source/main.rs"
|
path = "source/main.rs"
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
globset = "0.4.9"
|
globset = "0.4.9"
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub fn hooked_cli_reference(
|
||||||
for command_name in commands_to_document {
|
for command_name in commands_to_document {
|
||||||
let output = Command::new("cargo")
|
let output = Command::new("cargo")
|
||||||
.env("NO_COLOR", "1")
|
.env("NO_COLOR", "1")
|
||||||
.args(&["run", "-q", "--", command_name, "--help"])
|
.args(["run", "-q", "--", command_name, "--help"])
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let usage = str::from_utf8(&output.stdout).unwrap().trim().to_string();
|
let usage = str::from_utf8(&output.stdout).unwrap().trim().to_string();
|
||||||
|
@ -44,7 +44,7 @@ pub fn hooked_cli_reference(
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.insert("commands", &commands);
|
context.insert("commands", &commands);
|
||||||
write(
|
write(
|
||||||
&out_path,
|
out_path,
|
||||||
Tera::one_off(REFERENCE_TEMPLATE, &context, false)?,
|
Tera::one_off(REFERENCE_TEMPLATE, &context, false)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,6 @@
|
||||||
//!
|
//!
|
||||||
//! > **Git hooks manager.**
|
//! > **Git hooks manager.**
|
||||||
|
|
||||||
#![forbid(unsafe_code)]
|
|
||||||
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
|
|
||||||
|
|
||||||
use {
|
use {
|
||||||
clap::Parser,
|
clap::Parser,
|
||||||
color_eyre::{install, Result},
|
color_eyre::{install, Result},
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub fn plural(count: usize, singular: &str, plural: Option<&str>) -> String {
|
||||||
pub fn globset_from_strings(input: &[String]) -> Result<GlobSet> {
|
pub fn globset_from_strings(input: &[String]) -> Result<GlobSet> {
|
||||||
let mut builder = GlobSetBuilder::new();
|
let mut builder = GlobSetBuilder::new();
|
||||||
for glob in input {
|
for glob in input {
|
||||||
builder.add(Glob::new(&glob)?);
|
builder.add(Glob::new(glob)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.build().map_err(Into::into)
|
builder.build().map_err(Into::into)
|
||||||
|
|
|
@ -13,6 +13,9 @@ edition = "2021"
|
||||||
[lib]
|
[lib]
|
||||||
path = "source/lib.rs"
|
path = "source/lib.rs"
|
||||||
|
|
||||||
|
[lints]
|
||||||
|
workspace = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
color-eyre = "0.6.2"
|
color-eyre = "0.6.2"
|
||||||
toml = "0.5.9"
|
toml = "0.5.9"
|
||||||
|
|
|
@ -6,7 +6,9 @@ use serde::{Deserialize, Serialize};
|
||||||
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
|
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ExitAction {
|
pub enum ExitAction {
|
||||||
|
/// Regardless of the hook's exit code, allow Hooked to continue.
|
||||||
Continue,
|
Continue,
|
||||||
|
/// Stop on a non-zero hook exit code.
|
||||||
Stop,
|
Stop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::NoiseLevel;
|
||||||
|
|
||||||
/// General Hooked configuration.
|
/// General Hooked configuration.
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
#[serde(default, deny_unknown_fields)]
|
#[serde(default, deny_unknown_fields)]
|
||||||
|
@ -14,6 +16,9 @@ pub struct General {
|
||||||
/// The directory to use for hooks.
|
/// The directory to use for hooks.
|
||||||
pub directory: PathBuf,
|
pub directory: PathBuf,
|
||||||
|
|
||||||
|
/// The noise level tasks should output logs with by default.
|
||||||
|
pub noise_level: NoiseLevel,
|
||||||
|
|
||||||
/// Path to a script template for use with the install subcommand.
|
/// Path to a script template for use with the install subcommand.
|
||||||
pub template: Option<PathBuf>,
|
pub template: Option<PathBuf>,
|
||||||
}
|
}
|
||||||
|
@ -23,6 +28,7 @@ impl Default for General {
|
||||||
Self {
|
Self {
|
||||||
config: PathBuf::from("Hooked.toml"),
|
config: PathBuf::from("Hooked.toml"),
|
||||||
directory: PathBuf::from("hooks"),
|
directory: PathBuf::from("hooks"),
|
||||||
|
noise_level: NoiseLevel::default(),
|
||||||
template: None,
|
template: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,11 +9,13 @@ use {
|
||||||
|
|
||||||
mod exit_action;
|
mod exit_action;
|
||||||
mod general;
|
mod general;
|
||||||
|
mod noise_level;
|
||||||
mod pre_commit;
|
mod pre_commit;
|
||||||
mod task;
|
mod task;
|
||||||
|
|
||||||
pub use exit_action::*;
|
pub use exit_action::*;
|
||||||
pub use general::*;
|
pub use general::*;
|
||||||
|
pub use noise_level::*;
|
||||||
pub use pre_commit::*;
|
pub use pre_commit::*;
|
||||||
pub use task::*;
|
pub use task::*;
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
//! The noise level Hooked should output logs with.
|
||||||
|
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// The noise level Hooked should output logs with.
|
||||||
|
#[derive(Debug, Deserialize, Eq, PartialEq, Serialize)]
|
||||||
|
#[serde(rename_all = "snake_case")]
|
||||||
|
pub enum NoiseLevel {
|
||||||
|
/// Output only errors.
|
||||||
|
Quiet,
|
||||||
|
/// Output everything.
|
||||||
|
Loud,
|
||||||
|
/// Print a list of tasks and output warnings and errors, this is the default.
|
||||||
|
Standard,
|
||||||
|
/// The same as [`NoiseLevel::Standard`] except don't output task names or
|
||||||
|
/// warnings.
|
||||||
|
Minimal,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for NoiseLevel {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::Standard
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{ExitAction, Task};
|
use crate::{ExitAction, NoiseLevel, Task};
|
||||||
|
|
||||||
/// A pre-commit hook.
|
/// A pre-commit hook.
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
@ -11,6 +11,10 @@ pub struct PreCommit {
|
||||||
/// Display name for this hook.
|
/// Display name for this hook.
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
|
||||||
|
/// The noise level this task should output with.
|
||||||
|
#[serde(default)]
|
||||||
|
pub noise_level: NoiseLevel,
|
||||||
|
|
||||||
/// What to do when the hook exits with a non-zero status code.
|
/// What to do when the hook exits with a non-zero status code.
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub on_failure: ExitAction,
|
pub on_failure: ExitAction,
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
[general]
|
[general]
|
||||||
directory = "hooked"
|
directory = "hooked"
|
||||||
|
noise_level = "minimal"
|
||||||
template = "test.sh"
|
template = "test.sh"
|
||||||
|
|
||||||
[[pre_commit]]
|
[[pre_commit]]
|
||||||
name = "Pre Commit 1"
|
name = "Pre Commit 1"
|
||||||
|
noise_level = "quiet"
|
||||||
command = "exit 0"
|
command = "exit 0"
|
||||||
staged = ["*.txt"]
|
staged = ["*.txt"]
|
||||||
on_failure = "continue"
|
on_failure = "continue"
|
||||||
|
|
||||||
[[pre_commit]]
|
[[pre_commit]]
|
||||||
name = "Pre Commit 2"
|
name = "Pre Commit 2"
|
||||||
|
noise_level = "loud"
|
||||||
script = "test.sh"
|
script = "test.sh"
|
||||||
on_failure = "stop"
|
on_failure = "stop"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use {
|
use {
|
||||||
hooked_config::{Config, ExitAction, PreCommit, Task},
|
hooked_config::{Config, ExitAction, NoiseLevel, PreCommit, Task},
|
||||||
toml::to_string_pretty,
|
toml::to_string_pretty,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ use insta::assert_snapshot;
|
||||||
fn test_serialize() {
|
fn test_serialize() {
|
||||||
let pre_commit_command = PreCommit {
|
let pre_commit_command = PreCommit {
|
||||||
name: Some("Command Test".to_string()),
|
name: Some("Command Test".to_string()),
|
||||||
|
noise_level: NoiseLevel::Quiet,
|
||||||
on_failure: ExitAction::Continue,
|
on_failure: ExitAction::Continue,
|
||||||
staged: vec!["*.txt".to_string()],
|
staged: vec!["*.txt".to_string()],
|
||||||
task: Task {
|
task: Task {
|
||||||
|
@ -19,6 +20,7 @@ fn test_serialize() {
|
||||||
|
|
||||||
let pre_commit_script = PreCommit {
|
let pre_commit_script = PreCommit {
|
||||||
name: Some("Script Test".to_string()),
|
name: Some("Script Test".to_string()),
|
||||||
|
noise_level: NoiseLevel::Loud,
|
||||||
on_failure: ExitAction::Stop,
|
on_failure: ExitAction::Stop,
|
||||||
staged: vec![],
|
staged: vec![],
|
||||||
task: Task {
|
task: Task {
|
||||||
|
|
|
@ -6,11 +6,13 @@ Config {
|
||||||
general: General {
|
general: General {
|
||||||
config: "Hooked.toml",
|
config: "Hooked.toml",
|
||||||
directory: "hooks",
|
directory: "hooks",
|
||||||
|
noise_level: Standard,
|
||||||
template: None,
|
template: None,
|
||||||
},
|
},
|
||||||
pre_commit: [
|
pre_commit: [
|
||||||
PreCommit {
|
PreCommit {
|
||||||
name: None,
|
name: None,
|
||||||
|
noise_level: Standard,
|
||||||
on_failure: Stop,
|
on_failure: Stop,
|
||||||
staged: [],
|
staged: [],
|
||||||
task: Task {
|
task: Task {
|
||||||
|
|
|
@ -6,6 +6,7 @@ Config {
|
||||||
general: General {
|
general: General {
|
||||||
config: "Hooked.toml",
|
config: "Hooked.toml",
|
||||||
directory: "hooked",
|
directory: "hooked",
|
||||||
|
noise_level: Minimal,
|
||||||
template: Some(
|
template: Some(
|
||||||
"test.sh",
|
"test.sh",
|
||||||
),
|
),
|
||||||
|
@ -15,6 +16,7 @@ Config {
|
||||||
name: Some(
|
name: Some(
|
||||||
"Pre Commit 1",
|
"Pre Commit 1",
|
||||||
),
|
),
|
||||||
|
noise_level: Quiet,
|
||||||
on_failure: Continue,
|
on_failure: Continue,
|
||||||
staged: [
|
staged: [
|
||||||
"*.txt",
|
"*.txt",
|
||||||
|
@ -30,6 +32,7 @@ Config {
|
||||||
name: Some(
|
name: Some(
|
||||||
"Pre Commit 2",
|
"Pre Commit 2",
|
||||||
),
|
),
|
||||||
|
noise_level: Loud,
|
||||||
on_failure: Stop,
|
on_failure: Stop,
|
||||||
staged: [],
|
staged: [],
|
||||||
task: Task {
|
task: Task {
|
||||||
|
|
|
@ -5,15 +5,18 @@ expression: to_string_pretty(&config).unwrap()
|
||||||
[general]
|
[general]
|
||||||
config = 'Hooked.toml'
|
config = 'Hooked.toml'
|
||||||
directory = 'hooks'
|
directory = 'hooks'
|
||||||
|
noise_level = 'standard'
|
||||||
|
|
||||||
[[pre_commit]]
|
[[pre_commit]]
|
||||||
name = 'Command Test'
|
name = 'Command Test'
|
||||||
|
noise_level = 'quiet'
|
||||||
on_failure = 'continue'
|
on_failure = 'continue'
|
||||||
staged = ['*.txt']
|
staged = ['*.txt']
|
||||||
command = 'exit 0'
|
command = 'exit 0'
|
||||||
|
|
||||||
[[pre_commit]]
|
[[pre_commit]]
|
||||||
name = 'Script Test'
|
name = 'Script Test'
|
||||||
|
noise_level = 'loud'
|
||||||
on_failure = 'stop'
|
on_failure = 'stop'
|
||||||
staged = []
|
staged = []
|
||||||
script = 'test.sh'
|
script = 'test.sh'
|
||||||
|
|
Loading…
Reference in New Issue