aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/builder
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-02-10 21:15:11 +0100
committerWojtek Kosior <koszko@koszko.org>2022-02-10 21:15:11 +0100
commite8c1af86062dbef68837d17e2f17f4b3c975c85c (patch)
treec82825bbfb354f6847ff006a0c1a6afd80aba8d0 /src/hydrilla/builder
parentd49925b8d17d206a8edf5b537b64c2055dc697c4 (diff)
downloadhydrilla-builder-e8c1af86062dbef68837d17e2f17f4b3c975c85c.tar.gz
hydrilla-builder-e8c1af86062dbef68837d17e2f17f4b3c975c85c.zip
use parameters to click.Path instead of validating paths manually
Diffstat (limited to 'src/hydrilla/builder')
-rw-r--r--src/hydrilla/builder/__main__.py24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/hydrilla/builder/__main__.py b/src/hydrilla/builder/__main__.py
index 5b98202..32ac2d9 100644
--- a/src/hydrilla/builder/__main__.py
+++ b/src/hydrilla/builder/__main__.py
@@ -30,32 +30,22 @@ import click
from .build import Build
-def validate_dir_path(ctx, param, value):
- path = Path(value)
- if path.is_dir():
- return path.resolve()
-
- raise click.BadParameter(f'{param.human_readable_name} must be a directory path')
-
-def validate_path(ctx, param, value):
- return Path(value)
+dir_type = click.Path(exists=True, file_okay=False, resolve_path=True)
+index_type = click.Path(path_type=Path)
@click.command()
-@click.option('-s', '--srcdir', default='.', type=click.Path(),
- callback=validate_dir_path,
+@click.option('-s', '--srcdir', default='.', type=dir_type,
help='Source directory to build from.')
-@click.option('-i', '--index-json', default='index.json', type=click.Path(),
- callback=validate_path,
+@click.option('-i', '--index-json', default='index.json', type=index_type,
help='Path to file to be processed instead of index.json (if not absolute, resolved relative to srcdir).')
-@click.option('-d', '--dstdir', type=click.Path(), required=True,
- callback=validate_dir_path,
+@click.option('-d', '--dstdir', type=dir_type, required=True,
help='Destination directory to write built package files to.')
def preform_build(srcdir, index_json, dstdir):
"""
Build Hydrilla package from scrdir and write the resulting files under
dstdir.
"""
- build = Build(srcdir, index_json)
- build.write_package_files(dstdir)
+ build = Build(Path(srcdir), Path(index_json.decode()))
+ build.write_package_files(Path(dstdir))
preform_build()