diff --git a/src/python/OBis/obis/scripts/cli.py b/src/python/OBis/obis/scripts/cli.py index 4b256dee839de29124761f8c44c40d59a4c0df17..82a454c2c1a16593d30255d9fd6fb742db9b59e6 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()