A command-line utility for running commands in a subdirectory (e.g., linters on a monorepo) with a set of pre-commit hooks
Project description
run-in-subdirectory
A command-line utility for running commands in a subdirectory (e.g., linters on a monorepo) with a set of pre-commit hooks
Usage
pre-commit
-
Use
run-in-subdirectory
hook to run command in a subdirectory passed as the first argument:repos: - repo: https://github.com/egormkn/run-in-subdirectory rev: main hooks: - id: run-in-subdirectory alias: prettier name: Format code with Prettier args: ["client", "npx --no -- prettier -w -u"] types: [ text ] files: ^client/
-
Use one of
run-in-...-level-subdirectory
hooks to automatically extractfirst
,second
orthird
-level subdirectory from the file path passed as the last positional argument.Note that you should set
files
,types
andexclude
properties so that the hook only runs for files in that subdirectory.repos: - repo: https://github.com/egormkn/run-in-subdirectory rev: main hooks: - id: run-in-first-level-subdirectory alias: prettier name: Format code with Prettier args: ["npx --no -- prettier -w -u"] types: [ text ] files: ^client/
command-line
run-in-subdirectory
can also be used as a command-line utility:
pip install run-in-subdirectory
usage: run-in-subdirectory [-h] [-v] (-l LEVEL | -d DIRECTORY) executable [args ...]
Runs the command in a subdirectory and fixes paths in arguments.
positional arguments:
executable Executable to run
args Sequence of program arguments
options:
-h, --help show this help message and exit
-v, --verbose Print information about a command to be called
-l LEVEL, --level LEVEL
Subdirectory level (0 for top-level directory)
-d DIRECTORY, --directory DIRECTORY
Subdirectory within which the subprocess will be executed
example:
When this program is executed with the following command:
run-in-subdirectory -d client/ npx --no eslint client/src/index.ts
Then the command will be executed:
npx --no eslint src/index.ts
and the current working directory will be set to client/
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for run_in_subdirectory-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 414276ade0e9ba2aa9b1ec62228c131ee49cd32efc98b3732dc2966e047e1246 |
|
MD5 | e4f2001439d06544ce92b78ef4d7529d |
|
BLAKE2b-256 | fd3023647cc567d4fe3e28030fa1814873bc3f573742ca8adb14af135ce29961 |
Hashes for run_in_subdirectory-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f48ade7c999bd5b00f163ba383383a19ffdc60ea569bcdde2c75a1c11781a59d |
|
MD5 | f31fff0c5ed37a5eed127719d337848c |
|
BLAKE2b-256 | daedd2084322fe742626fe2558b0e2be1321e8dcc3268e717c79e9c2b4d769a4 |