Compare commits
No commits in common. "82cbc580dcb5528d1399a88e761b0995acefa445" and "a4d0431a32fc9e6f0d41e164bea6e34b66cbe9cd" have entirely different histories.
82cbc580dc
...
a4d0431a32
|
@ -1,42 +0,0 @@
|
|||
This file is automatically generated using the cli-reference subcommand.
|
||||
Use `cargo run -- cli-reference` to generate it.
|
||||
|
||||
// ANCHOR: install
|
||||
$ hooked install --help
|
||||
Install Hooked into ".git/hooks"
|
||||
|
||||
Usage: hooked install [OPTIONS]
|
||||
|
||||
Options:
|
||||
--overwrite Overwrite existing files
|
||||
-c, --config <CONFIG> Path to a Hooked configuration [default: Hooked.toml]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
// ANCHOR_END: install
|
||||
// ANCHOR: run
|
||||
$ hooked run --help
|
||||
Manually run hooks
|
||||
|
||||
Usage: hooked run [OPTIONS] <HOOK_TYPE>
|
||||
|
||||
Arguments:
|
||||
<HOOK_TYPE> The hook type to run [possible values: pre-commit]
|
||||
|
||||
Options:
|
||||
-c, --config <CONFIG> Path to a Hooked configuration [default: Hooked.toml]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
// ANCHOR_END: run
|
||||
// ANCHOR: uninstall
|
||||
$ hooked uninstall --help
|
||||
Remove installed hooks
|
||||
|
||||
Usage: hooked uninstall [OPTIONS]
|
||||
|
||||
Options:
|
||||
--all Remove hooks not installed by Hooked
|
||||
-c, --config <CONFIG> Path to a Hooked configuration [default: Hooked.toml]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
// ANCHOR_END: uninstall
|
||||
|
|
@ -3,7 +3,16 @@
|
|||
The `install` command creates the scripts inside `.git/hooks`.
|
||||
|
||||
```sh
|
||||
{{#include ../cli-reference.txt:install}}
|
||||
$ hooked install --help
|
||||
Install Hooked into ".git/hooks"
|
||||
|
||||
Usage: hooked install [OPTIONS]
|
||||
|
||||
Options:
|
||||
--overwrite Overwrite existing files
|
||||
-c, --config <CONFIG> Path to a Hooked configuration [default: Hooked.toml]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
```
|
||||
|
||||
Below is the default script template that Hooked uses, where `hook_type` is the type of hook to run (like `pre-commit`) and `config_path` is the `general.config` field from the parsed configuration.
|
||||
|
|
|
@ -2,6 +2,17 @@
|
|||
|
||||
The `run` command manually runs configured hooks.
|
||||
|
||||
```sh
|
||||
{{#include ../cli-reference.txt:run}}
|
||||
```
|
||||
$ hooked run --help
|
||||
Manually run hooks
|
||||
|
||||
Usage: hooked run [OPTIONS] <HOOK_TYPE>
|
||||
|
||||
Arguments:
|
||||
<HOOK_TYPE> The hook type to run [possible values: pre-commit]
|
||||
|
||||
Options:
|
||||
-c, --config <CONFIG> Path to a Hooked configuration [default: Hooked.toml]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
```
|
||||
|
|
|
@ -3,7 +3,16 @@
|
|||
The `uninstall` command removes script files inside `.git/hooks`.
|
||||
|
||||
```sh
|
||||
{{#include ../cli-reference.txt:uninstall}}
|
||||
hooked uninstall --help
|
||||
Remove installed hooks
|
||||
|
||||
Usage: hooked uninstall [OPTIONS]
|
||||
|
||||
Options:
|
||||
--all Remove hooks not installed by Hooked
|
||||
-c, --config <CONFIG> Path to a Hooked configuration [default: Hooked.toml]
|
||||
-h, --help Print help information
|
||||
-V, --version Print version information
|
||||
```
|
||||
|
||||
By default Hooked will only remove scripts that have a `# Installed by Hooked.` line in them, using `--all` however will remove all script files.
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
//! The `cli-reference` subcommand, only available in debug mode.
|
||||
|
||||
use std::{fs::write, process::Command, str};
|
||||
|
||||
use {
|
||||
color_eyre::Result,
|
||||
hooked_config::Config,
|
||||
tera::{Context, Tera},
|
||||
};
|
||||
|
||||
use crate::cli::CliReferenceArgs;
|
||||
|
||||
const REFERENCE_TEMPLATE: &str = include_str!("../templates/cli-reference.txt");
|
||||
|
||||
/// The `cli-reference` subcommand.
|
||||
pub fn hooked_cli_reference(
|
||||
_config: Config,
|
||||
args: CliReferenceArgs,
|
||||
) -> Result<()> {
|
||||
let out_path = if args.output.is_dir() {
|
||||
args.output.join("cli-reference.txt")
|
||||
} else {
|
||||
args.output
|
||||
};
|
||||
|
||||
let commands = {
|
||||
let mut commands = vec![];
|
||||
let commands_to_document = &["install", "run", "uninstall"];
|
||||
|
||||
for command_name in commands_to_document {
|
||||
let output = Command::new("cargo")
|
||||
.env("NO_COLOR", "1")
|
||||
.args(&["run", "-q", "--", command_name, "--help"])
|
||||
.output()
|
||||
.unwrap();
|
||||
let usage = str::from_utf8(&output.stdout).unwrap().trim().to_string();
|
||||
commands.push((command_name.to_string(), usage))
|
||||
}
|
||||
|
||||
commands
|
||||
};
|
||||
|
||||
let mut context = Context::new();
|
||||
context.insert("commands", &commands);
|
||||
write(
|
||||
&out_path,
|
||||
Tera::one_off(REFERENCE_TEMPLATE, &context, false)?,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -4,14 +4,10 @@ use std::path::PathBuf;
|
|||
|
||||
use clap::{Args as Arguments, Parser, Subcommand};
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
mod cli_reference;
|
||||
mod install;
|
||||
mod run;
|
||||
mod uninstall;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
pub use cli_reference::hooked_cli_reference;
|
||||
pub use install::hooked_install;
|
||||
pub use run::hooked_run;
|
||||
pub use uninstall::hooked_uninstall;
|
||||
|
@ -41,10 +37,6 @@ pub enum MainSubcommands {
|
|||
|
||||
/// Manually run hooks.
|
||||
Run(RunArgs),
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
/// Generate the CLI reference file for the mdBook.
|
||||
CliReference(CliReferenceArgs),
|
||||
}
|
||||
|
||||
/// The `install` subcommand arguments.
|
||||
|
@ -70,11 +62,3 @@ pub struct RunArgs {
|
|||
#[clap(value_parser = crate::HOOK_TYPES)]
|
||||
pub hook_type: String,
|
||||
}
|
||||
|
||||
/// The `cli-reference` subcommand arguments.
|
||||
#[derive(Debug, Arguments)]
|
||||
pub struct CliReferenceArgs {
|
||||
/// Path where the CLI reference file should be generated.
|
||||
#[clap(short, long, default_value = "hooked-book/source/")]
|
||||
pub output: PathBuf,
|
||||
}
|
||||
|
|
|
@ -40,11 +40,6 @@ fn main() -> Result<()> {
|
|||
MainSubcommands::Run(sub_args) => {
|
||||
cli::hooked_run(config, sub_args.hook_type)?;
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
MainSubcommands::CliReference(sub_args) => {
|
||||
cli::hooked_cli_reference(config, sub_args)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,11 +0,0 @@
|
|||
This file is automatically generated using the cli-reference subcommand.
|
||||
Use `cargo run -- cli-reference` to generate it.
|
||||
|
||||
{% for command in commands %}
|
||||
{%- set name = command.0 -%}
|
||||
{%- set usage = command.1 -%}
|
||||
// ANCHOR: {{ name }}
|
||||
$ hooked {{ name }} --help
|
||||
{{ usage }}
|
||||
// ANCHOR_END: {{ name }}
|
||||
{% endfor %}
|
Loading…
Reference in New Issue