Skip to content

Commit e66eb22

Browse files
Various CLI refinements
Closes #101
1 parent 2dea8b5 commit e66eb22

File tree

2 files changed

+299
-74
lines changed

2 files changed

+299
-74
lines changed

bio2zarr/cli.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
logger = logging.getLogger(__name__)
1717

18+
1819
class NaturalOrderGroup(click.Group):
1920
"""
2021
List commands in the order they are provided in the help text.
@@ -29,12 +30,27 @@ def list_commands(self, ctx):
2930
"vcfs", nargs=-1, required=True, type=click.Path(exists=True, dir_okay=False)
3031
)
3132

32-
icf_path = click.argument("icf_path", type=click.Path(file_okay=False, dir_okay=True))
33+
new_icf_path = click.argument(
34+
"icf_path", type=click.Path(file_okay=False, dir_okay=True)
35+
)
36+
37+
icf_path = click.argument(
38+
"icf_path", type=click.Path(exists=True, file_okay=False, dir_okay=True)
39+
)
40+
41+
new_zarr_path = click.argument(
42+
"zarr_path", type=click.Path(file_okay=False, dir_okay=True)
43+
)
3344

3445
verbose = click.option("-v", "--verbose", count=True, help="Increase verbosity")
3546

36-
force = click.option("-f", "--force", is_flag=True, flag_value=True,
37-
help="Force overwriting of existing directories")
47+
force = click.option(
48+
"-f",
49+
"--force",
50+
is_flag=True,
51+
flag_value=True,
52+
help="Force overwriting of existing directories",
53+
)
3854

3955
version = click.version_option(version=f"{provenance.__version__}")
4056

@@ -84,7 +100,10 @@ def check_overwrite_dir(path, force):
84100
path = pathlib.Path(path)
85101
if path.exists():
86102
if not force:
87-
click.confirm(f"Do you want to overwrite {path}? (use --force to skip this check)")
103+
click.confirm(
104+
f"Do you want to overwrite {path}? (use --force to skip this check)",
105+
abort=True,
106+
)
88107
# These trees can be mondo-big and on slow file systems, so it's entirely
89108
# feasible that the delete would fail or be killed. This makes it less likely
90109
# that partially deleted paths are mistaken for good paths.
@@ -96,7 +115,7 @@ def check_overwrite_dir(path, force):
96115

97116
@click.command
98117
@vcfs
99-
@icf_path
118+
@new_icf_path
100119
@force
101120
@verbose
102121
@worker_processes
@@ -118,8 +137,8 @@ def explode(vcfs, icf_path, force, verbose, worker_processes, column_chunk_size)
118137

119138
@click.command
120139
@vcfs
121-
@icf_path
122-
@click.argument("num_partitions", type=int)
140+
@new_icf_path
141+
@click.argument("num_partitions", type=click.IntRange(min=1))
123142
@force
124143
@column_chunk_size
125144
@verbose
@@ -146,7 +165,7 @@ def dexplode_init(
146165

147166
@click.command
148167
@icf_path
149-
@click.argument("partition", type=int)
168+
@click.argument("partition", type=click.IntRange(min=0))
150169
@verbose
151170
def dexplode_partition(icf_path, partition, verbose):
152171
"""
@@ -193,7 +212,8 @@ def mkschema(icf_path):
193212

194213
@click.command
195214
@icf_path
196-
@click.argument("zarr_path", type=click.Path())
215+
@new_zarr_path
216+
@force
197217
@verbose
198218
@click.option("-s", "--schema", default=None, type=click.Path(exists=True))
199219
@variants_chunk_size
@@ -220,6 +240,7 @@ def mkschema(icf_path):
220240
def encode(
221241
icf_path,
222242
zarr_path,
243+
force,
223244
verbose,
224245
schema,
225246
variants_chunk_size,
@@ -232,10 +253,11 @@ def encode(
232253
Encode intermediate columnar format (see explode) to vcfzarr.
233254
"""
234255
setup_logging(verbose)
256+
check_overwrite_dir(zarr_path, force)
235257
vcf.encode(
236258
icf_path,
237259
zarr_path,
238-
schema,
260+
schema_path=schema,
239261
variants_chunk_size=variants_chunk_size,
240262
samples_chunk_size=samples_chunk_size,
241263
max_v_chunks=max_variant_chunks,
@@ -247,7 +269,7 @@ def encode(
247269

248270
@click.command(name="convert")
249271
@vcfs
250-
@click.argument("zarr_path", type=click.Path())
272+
@new_zarr_path
251273
@variants_chunk_size
252274
@samples_chunk_size
253275
@verbose

0 commit comments

Comments
 (0)