Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: generic subprocess #1037

Closed
ericfrederich opened this issue Apr 12, 2024 · 2 comments
Closed

proposal: generic subprocess #1037

ericfrederich opened this issue Apr 12, 2024 · 2 comments

Comments

@ericfrederich
Copy link
Contributor

I'm happy to implement this if it is acceptable.

I think it would be useful to be able to run subprocess specified by the configuration against files.

I thought of this idea because currently the pre-commit-terraform hooks are implemented in Bash which is fine for Linux systems, or Windows if you're using WSL or Git Bash, but it fails from powershell or a regular command prompt.
I'm working with them to port hooks from bash to Python (since pre-commit is Python based anyway).

While I wait for this PR to maybe get accepted, I was thinking it would be nice if this pre-commit-hooks repo had a hook where you could just specify a generic command.

Maybe it could behave similar to something like Bash's xargs. Maybe even give the hook the id of xargs?

Example:

repos:
-   repo: https://github.com/pre-commit/pre-commit-hooks
    rev: vX.Y.Z
    hooks:
    # run terraform fmt against all .tf and .tfvars files
    -   id: xargs
        args: ["terraform", "fmt"]
        files: \.tf(vars)?$
        exclude: \.terraform/.*$
@asottile
Copy link
Member

is that not what repo: local let's you do?

@ericfrederich
Copy link
Contributor Author

Ah, nice, thanks... repo: local and language: system

- repo: local
  hooks:
  - id: terraform_fmt
    name: Terraform fmt
    description: Rewrites all Terraform configuration files to a canonical format.
    entry: terraform fmt
    language: system
    files: (\.tf|\.tfvars)$
    exclude: \.terraform/.*$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants