Revision e8c1af86
Added by koszko over 1 year ago
src/hydrilla/builder/__main__.py | ||
---|---|---|
30 | 30 |
|
31 | 31 |
from .build import Build |
32 | 32 |
|
33 |
def validate_dir_path(ctx, param, value): |
|
34 |
path = Path(value) |
|
35 |
if path.is_dir(): |
|
36 |
return path.resolve() |
|
37 |
|
|
38 |
raise click.BadParameter(f'{param.human_readable_name} must be a directory path') |
|
39 |
|
|
40 |
def validate_path(ctx, param, value): |
|
41 |
return Path(value) |
|
33 |
dir_type = click.Path(exists=True, file_okay=False, resolve_path=True) |
|
34 |
index_type = click.Path(path_type=Path) |
|
42 | 35 |
|
43 | 36 |
@click.command() |
44 |
@click.option('-s', '--srcdir', default='.', type=click.Path(), |
|
45 |
callback=validate_dir_path, |
|
37 |
@click.option('-s', '--srcdir', default='.', type=dir_type, |
|
46 | 38 |
help='Source directory to build from.') |
47 |
@click.option('-i', '--index-json', default='index.json', type=click.Path(), |
|
48 |
callback=validate_path, |
|
39 |
@click.option('-i', '--index-json', default='index.json', type=index_type, |
|
49 | 40 |
help='Path to file to be processed instead of index.json (if not absolute, resolved relative to srcdir).') |
50 |
@click.option('-d', '--dstdir', type=click.Path(), required=True, |
|
51 |
callback=validate_dir_path, |
|
41 |
@click.option('-d', '--dstdir', type=dir_type, required=True, |
|
52 | 42 |
help='Destination directory to write built package files to.') |
53 | 43 |
def preform_build(srcdir, index_json, dstdir): |
54 | 44 |
""" |
55 | 45 |
Build Hydrilla package from scrdir and write the resulting files under |
56 | 46 |
dstdir. |
57 | 47 |
""" |
58 |
build = Build(srcdir, index_json)
|
|
59 |
build.write_package_files(dstdir)
|
|
48 |
build = Build(Path(srcdir), Path(index_json.decode()))
|
|
49 |
build.write_package_files(Path(dstdir))
|
|
60 | 50 |
|
61 | 51 |
preform_build() |
Also available in: Unified diff
use parameters to click.Path instead of validating paths manually