Skip to content

Commit d37abf3

Browse files
committed
feat(cli): configurable format of dataset output
1 parent 575686b commit d37abf3

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

renku/cli/dataset.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,37 +82,61 @@
8282
import click
8383
from click import BadParameter
8484

85-
from renku.models._tabulate import tabulate
86-
from renku.models.datasets import Author
87-
8885
from ._client import pass_local_client
8986
from ._echo import progressbar
9087

9188

89+
def _tabular(client, datasets=None):
90+
"""Format datasets with a tabular output."""
91+
from renku.models._tabulate import tabulate
92+
93+
datasets = datasets or client.datasets
94+
95+
click.echo(
96+
tabulate(
97+
datasets.values(),
98+
headers=OrderedDict((
99+
('short_id', 'id'),
100+
('name', None),
101+
('created', None),
102+
('authors_csv', 'authors'),
103+
)),
104+
)
105+
)
106+
107+
108+
FORMATS = {
109+
'tabular': _tabular,
110+
}
111+
112+
92113
@click.group(invoke_without_command=True)
93114
@click.option('--datadir', default='data', type=click.Path(dir_okay=True))
115+
@click.option(
116+
'--format',
117+
type=click.Choice(FORMATS),
118+
default='tabular',
119+
help='Choose an output format.'
120+
)
94121
@pass_local_client(clean=False, commit=False)
95122
@click.pass_context
96-
def dataset(ctx, client, datadir):
123+
def dataset(ctx, client, datadir, format):
97124
"""Handle datasets."""
98125
ctx.meta['renku.datasets.datadir'] = datadir
99126

100127
if ctx.invoked_subcommand is not None:
101128
return
102129

103-
output = tabulate(
104-
client.datasets.values(),
105-
headers=OrderedDict((('short_id', 'id'), ('name', None),
106-
('created', None), ('authors_csv', 'authors'))),
107-
)
108-
click.echo(output)
130+
FORMATS[format](client)
109131

110132

111133
@dataset.command()
112134
@click.argument('name')
113135
@pass_local_client(clean=True, commit=True)
114136
def create(client, name):
115137
"""Create an empty dataset in the current repo."""
138+
from renku.models.datasets import Author
139+
116140
with client.with_dataset(name=name) as dataset:
117141
click.echo('Creating a dataset ... ', nl=False)
118142
author = Author.from_git(client.repo)

0 commit comments

Comments
 (0)