Skip to content

Commit

Permalink
feat(cli): enable only and repeat options
Browse files Browse the repository at this point in the history
  • Loading branch information
yshalenyk committed May 15, 2021
1 parent 22c63f8 commit 8b82f9e
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions spoonbill/cli.py
Expand Up @@ -8,7 +8,7 @@
from ocdskit.util import detect_format

from spoonbill import FileAnalyzer, FileFlattener
from spoonbill.common import COMBINED_TABLES, ROOT_TABLES
from spoonbill.common import COMBINED_TABLES, ROOT_TABLES, TABLE_THRESHOLD
from spoonbill.flatten import FlattenOptions
from spoonbill.i18n import _
from spoonbill.utils import resolve_file_uri
Expand Down Expand Up @@ -41,7 +41,7 @@ def get_selected_tables(base, selection):
return {name: tab for name, tab in base.items() if name in selection}


def should_split(spec, table_name, split, threshold=5):
def should_split(spec, table_name, split, threshold=TABLE_THRESHOLD):
table = spec.tables[table_name]
if table_name in split:
return True
Expand All @@ -61,6 +61,12 @@ def should_split(spec, table_name, split, threshold=5):
type=CommaSeparated(),
default="",
)
@click.option(
"--threshold",
help=_("Maximum number of elements in array before its spitted into table"),
type=int,
default=TABLE_THRESHOLD,
)
@click.option(
"--state-file",
help=_("Uri to previously generated state file"),
Expand All @@ -80,16 +86,15 @@ def should_split(spec, table_name, split, threshold=5):
default="",
)
@click.option("--combine", help=_("Combine same objects to single table"), type=CommaSeparated())
@click.option("--only", help=_("Specify which fields to output"), type=CommaSeparated())
@click.option("--only", help=_("Specify which fields to output"), type=CommaSeparated(), default="")
@click.option(
"--repeat",
help=_("Repeat a column from a parent sheet onto child tables"),
type=CommaSeparated(),
default="",
)
@click.option(
"--count",
help=_("For each array field, add a count column to the parent table"),
is_flag=True,
"--count", help=_("For each array field, add a count column to the parent table"), is_flag=True, default=False
)
@click.option(
"--human",
Expand All @@ -102,6 +107,7 @@ def cli(
schema,
selection,
split,
threshold,
state_file,
xlsx,
csv,
Expand Down Expand Up @@ -194,10 +200,14 @@ def cli(
click.echo(_("Ignoring empty table {}").format(click.style(name, fg="red")))
continue
unnest = [col for col in unnest if col in table]
only = [col for col in only if col in table]
repeat = [col for col in repeat if col in table]
options["selection"][name] = {
"split": should_split(analyzer.spec, name, split),
"pretty_headers": human,
"unnest": unnest,
"only": only,
"repeat": repeat,
}
options = FlattenOptions(**options)
all_tables = chain(options.selection.keys(), combined_tables.keys())
Expand Down

0 comments on commit 8b82f9e

Please sign in to comment.