implemented --tool flag to allow arbirary arguments to be passed #3618
+46
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We are using pre-commit as part of our python CI pipeline and often find we would like to use the really nice dependency management of pre-commit to include tools in various projects and invoke them in the terminal with arbitrary arguments.
Most of our tools are performing pure validation in the CI (we have a
--validateflag we use with pre-commit) , but these tools expose other features useful to the developer.Currently pre-commit only allows usage of the hook as a 'tool' in the terminal with
pre-commit run example-hookIf we wanted different arguments passed to different invocations this requires defining each permutation as a separate entry in the
.pre-commit.config.yamlwith specific predefined arguments inargs:[...], which does not support using the hook as a tool with dynamic arguments.Without having to have yet another solution to use our hooks as tools in the terminal, given pre-commit already provides 99% of the functionality we have added a
--toolflag to our internal build of pre-commit.--toolimpliesallow_all_files=true(this is a choice for our use cases but would work either way) and requires the hook is exposed forstages:["manual"].A hook can be invoked as a tool with any arbitrary arguments using:
pre-commit run example-hook --tool -- --arg1 --arg2=4 ...