Skip to content

Commit 054fa5f

Browse files
committed
Created CLI options --path + --max-depth + --markers
1 parent 14bb21d commit 054fa5f

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

find-project-root/docs/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,43 @@ CLI options:
9595

9696
| Option | Description
9797
| ------------------- | ------------------------------------
98+
| `-p`, `--path` | Starting dir to search for project root (default: CWD)
99+
| `-d`, `--max-depth` | Max levels to traverse up (default: 9)
100+
| `-m`, `--markers` | Custom marker files to look for (default: [`project-markers`][project-markers-json] list)
98101
| `-h`, `--help` | Show help screen
99102
| `-v`, `--version` | Show version
100103
| `--docs` | Open docs URL
101104

102105
<hr>
103106

107+
### Examples:
108+
109+
Start from specific path:
110+
111+
```bash
112+
find-project-root --path="assets/images"
113+
```
114+
115+
Limit search depth:
116+
117+
```bash
118+
find-project-root --max_depth=3
119+
```
120+
121+
Use custom markers:
122+
123+
```bash
124+
find-project-root --markers=.git,pyproject.toml,requirements.txt
125+
```
126+
127+
Combine options:
128+
129+
```bash
130+
find-project-root --path=src --max-depth=5 --markers=.manifest.json
131+
```
132+
133+
<hr>
134+
104135

105136
## MIT License
106137

find-project-root/src/find_project_root/cli/__main__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,18 @@
55

66
def main():
77
cli = init.cli()
8+
settings.load(cli)
89

910
# Process early-exit args (e.g. --help, --version)
1011
for ctrl_name, ctrl in vars(settings.controls).items():
1112
if getattr(ctrl, 'exit', False) and getattr(cli.config, ctrl_name, False):
1213
if hasattr(ctrl, 'handler') : ctrl.handler(cli)
1314
sys.exit(0)
1415

15-
print(find_project_root())
16+
print(find_project_root(
17+
path=getattr(cli.config, 'path', None),
18+
max_depth=getattr(cli.config, 'max_depth', 9),
19+
markers=getattr(cli.config, 'markers', None)
20+
))
1621

1722
if __name__ == '__main__' : main()

find-project-root/src/find_project_root/cli/lib/settings.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
from . import log, string, url
66

77
controls = sn(
8+
path=sn(
9+
args=['-p', '--path'], action='store', metavar='DIR'),
10+
depth=sn(
11+
args=['-d', '--max-depth'], action='store', type=int, default=9, metavar='N'),
12+
markers=sn(
13+
args=['-m', '--markers'], metavar='MARKER', type=str, parser='csv'),
814
help=sn(
915
args=['-h', '--help'], action='help'),
1016
version=sn(

find-project-root/src/find_project_root/data/package_data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@
2121
"support": "https://github.com/adamlui/python-utils/issues"
2222
},
2323
"commit_hashes": {
24-
"locales": "a9d6e65"
24+
"locales": "b906aaa"
2525
}
2626
}

0 commit comments

Comments
 (0)