Skip to content

Commit

Permalink
Add cli for tables_io.convert (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
sidneymau authored Apr 25, 2024
1 parent 779098d commit 86439b6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ dev = [
"sphinx-autoapi", # Used to automatically generate api documentation
]

[project.scripts]
convert-table = "tables_io.cli:main"

[build-system]
requires = [
"setuptools>=62", # Used to build and package the Python project
Expand Down
41 changes: 41 additions & 0 deletions src/tables_io/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""cli for tables_io.convert"""

import argparse

import tables_io


def get_args():
parser = argparse.ArgumentParser()
parser.add_argument(
"input",
type=str,
help=f"input filename; suffix should be one of {list(tables_io.types.FILE_FORMAT_SUFFIXS.keys())}",
)
parser.add_argument(
"output",
type=str,
help=f"output filename; suffix should be one of {list(tables_io.types.FILE_FORMAT_SUFFIXS.keys())}",
)
return parser.parse_args()


def main():
args = get_args()

input_fname = args.input
output_fname = args.output
output_format = output_fname.split(".")[-1]

print(f"Converting {input_fname} to {output_fname}")

suffixes = tables_io.types.FILE_FORMAT_SUFFIXS
suffix = suffixes[output_format]

t_in = tables_io.read(input_fname)
t_out = tables_io.convert(t_in, suffix)
written = tables_io.write(t_out, output_fname)

print(f"Done converting file")

return 0

0 comments on commit 86439b6

Please sign in to comment.