From c343a5622205b0dc4ade76a477cb2d4bce1fa8a2 Mon Sep 17 00:00:00 2001
From: vermeul <swen@ethz.ch>
Date: Mon, 24 Oct 2022 15:58:23 +0200
Subject: [PATCH] fixed changelog

---
 pybis/src/python/CHANGELOG.md |  4 ++++
 pybis/src/python/pybis/cli.py | 42 ++++++++++++++++++++++++++++++-----
 pybis/src/python/setup.cfg    |  6 ++++-
 3 files changed, 46 insertions(+), 6 deletions(-)

diff --git a/pybis/src/python/CHANGELOG.md b/pybis/src/python/CHANGELOG.md
index 336d0ad92bb..0da0f92c27a 100644
--- a/pybis/src/python/CHANGELOG.md
+++ b/pybis/src/python/CHANGELOG.md
@@ -1,3 +1,7 @@
+## Changes with pybis-1.34.0
+
+- add experimental support for datasets via cli
+
 ## Changes with pybis-1.33.2
 
 - fix openbis.support.email key error
diff --git a/pybis/src/python/pybis/cli.py b/pybis/src/python/pybis/cli.py
index df8a5547156..c70dc522da2 100644
--- a/pybis/src/python/pybis/cli.py
+++ b/pybis/src/python/pybis/cli.py
@@ -130,17 +130,49 @@ def dataset(ctx):
 @click.argument("permid", required=True)
 def get_dataset(permid, **kwargs):
     """get a dataset by its permId"""
-    print(permid)
-    print(kwargs)
     openbis = get_openbis(**kwargs)
-    print(openbis)
+    ds = openbis.get_dataset(permid)
+    click.echo(ds.__repr__())
+    click.echo("")
+    click.echo("Files in this dataset")
+    click.echo("---------------------")
+    click.echo(ds.get_files())
 
 
 @dataset.command("download")
+@openbis_conn_options
 @click.argument("permid", required=True)
-def download_dataset(permid, **kwargs):
+@click.argument("fileno", nargs=-1)
+@click.option(
+    "--destination",
+    "-d",
+    type=click.Path(exists=True),
+    help="where to download your dataset",
+)
+def download_dataset(permid, destination, fileno, **kwargs):
     """download a dataset by permId"""
-    click.echo(permid)
+    openbis = get_openbis(**kwargs)
+    try:
+        ds = openbis.get_dataset(permid)
+    except ValueError as exc:
+        raise click.ClickException(exc)
+
+    create_default_folders = False if destination else True
+    if fileno:
+        all_files = ds.get_files()
+        files = []
+        for loc in fileno:
+            files.append(all_files.loc[int(loc)]["pathInDataSet"])
+        print(files)
+        ds.download(
+            destination=destination,
+            create_default_folders=create_default_folders,
+            files=files,
+        )
+    else:
+        ds.download(
+            destination=destination, create_default_folders=create_default_folders
+        )
 
 
 @cli.command("local", context_settings=dict(ignore_unknown_options=True))
diff --git a/pybis/src/python/setup.cfg b/pybis/src/python/setup.cfg
index 08a6139ae22..a964880f886 100644
--- a/pybis/src/python/setup.cfg
+++ b/pybis/src/python/setup.cfg
@@ -1,6 +1,6 @@
 [metadata]
 name = PyBIS
-version = 1.33.2
+version = 1.34.0rc1
 author = Swen Vermeul • ID SIS • ETH Zürich
 author_email = swen@ethz.ch
 license = Apache Software License Version 2.0
@@ -13,6 +13,10 @@ classifiers =
     License :: OSI Approved :: Apache Software License
     Operating System :: OS Independent
 
+[options.entry_points]
+console_scripts =
+    pybis = pybis.cli:cli
+
 [options]
 packages = find:
 install_requires =
-- 
GitLab