From 7ee78564c761ca72cd151ef9a86f775d949a18c1 Mon Sep 17 00:00:00 2001
From: Yves Noirjean <ynoir@bsse-vpn-249.ethz.ch>
Date: Mon, 16 Oct 2017 12:16:09 +0200
Subject: [PATCH] obis: added option to set experiment id when obis init

---
 src/python/OBis/obis/scripts/cli.py | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/python/OBis/obis/scripts/cli.py b/src/python/OBis/obis/scripts/cli.py
index 4b256dee839..82a454c2c1a 100644
--- a/src/python/OBis/obis/scripts/cli.py
+++ b/src/python/OBis/obis/scripts/cli.py
@@ -131,37 +131,41 @@ def set_property(data_mgmt, prop, value, is_global):
         return CommandResult(returncode=0, output="")
 
 
-def init_data_impl(ctx, sample_id, folder, name):
+def init_data_impl(ctx, sample_id, experiment_id, folder, name):
     """Shared implementation for the init_data command."""
     click_echo("init_data {}".format(folder))
     data_mgmt = shared_data_mgmt(ctx.obj)
     name = name if name != "" else None
     result = data_mgmt.init_data(folder, name, create=True)
-    if not sample_id or result.failure():
+    if (not sample_id and not experiment_id) or result.failure():
         return check_result("init_data", result)
     with dm.cd(folder):
-        return check_result("init_data", set_property(data_mgmt, 'sample_id', sample_id, False))
+        if sample_id:
+            return check_result("init_data", set_property(data_mgmt, 'sample_id', sample_id, False))
+        if experiment_id:
+            return check_result("init_data", set_property(data_mgmt, 'experiment_id', experiment_id, False))
+
 
-# TODO test and add param for experiment
 @cli.command()
 @click.pass_context
-@click.option('-o', '--sample_id', help='Set the id of the owning object.')
+@click.option('-si', '--sample_id', help='Set the id of the owning sample.')
+@click.option('-ei', '--experiment_id', help='Set the id of the owning experiment.')
 @click.argument('folder', type=click.Path(exists=False, file_okay=False))
 @click.argument('name', default="")
-def init(ctx, sample_id, folder, name):
+def init(ctx, sample_id, experiment_id, folder, name):
     """Initialize the folder as a data folder (alias for init_data)."""
-    return init_data_impl(ctx, sample_id, folder, name)
+    return init_data_impl(ctx, sample_id, experiment_id, folder, name)
 
 
-# TODO test and add param for experiment
 @cli.command()
 @click.pass_context
-@click.option('-o', '--sample_id', help='Set the id of the owning object.')
+@click.option('-si', '--sample_id', help='Set the id of the owning sample.')
+@click.option('-ei', '--experiment_id', help='Set the id of the owning experiment.')
 @click.argument('folder', type=click.Path(exists=False, file_okay=False))
 @click.argument('name', default="")
-def init_data(ctx, sample_id, folder, name):
+def init_data(ctx, sample_id, experiment_id, folder, name):
     """Initialize the folder as a data folder."""
-    return init_data_impl(ctx, sample_id, folder, name)
+    return init_data_impl(ctx, sample_id, experiment_id, folder, name)
 
 
 @cli.command()
-- 
GitLab