-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
A-configurationArea: cargo config files and env varsArea: cargo config files and env varsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.
Description
Problem
My original intention, if this feature ever becomes available, is to automatically note dependency changes in a project's changelog with every command.
Proposed Solution
Hi there, coming from the python ecosystem, I'm used to having custom hooks running on dependency changes using poetry's plugin system. I was wondering if we could add the same capability to cargo.
I propose we add a new mapping to Cargo.toml
manifests (and workspaces):
[hooks]
before_command="..."
after_command="..."
If these options are specified in Cargo.toml
s, then cargo
will execute the path specified, with the same arguments provided to cargo
, as a child process, before and after any cargo command executes, respectively.
- If the env var
CARGO_SKIP_HOOKS
is set to "1", cargo will skip running the hooks. Users could use this flag to callcargo
from inside their hooks without the risk of infinite recursion. - If the
before_command
hook fails (exists with a non-zero status), cargo will not execute the command, and exit with a non-zero code. - If the
cargo
command itself fails, theafter_command
hook will not be called (a special hook for command failures may be considered in the future) - If the
after_command
hook fails, cargo will exit with a non-zero code.
Notes
For example, with the Cargo.toml
[package]
...
[hooks]
before_command="foo"
after_command="bar"
Then, when calling cargo add regex
, cargo
will do the following
- execute a child process with executable
foo
with argumentsadd regex
- add the
regex
crate dependency to the package, as normal - execute a child process with executable
bar
with argumentsadd regex
Metadata
Metadata
Assignees
Labels
A-configurationArea: cargo config files and env varsArea: cargo config files and env varsC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`S-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.