cli: make config cli args functions return a status enum
[babeltrace.git] / src / cli / babeltrace2-cfg-cli-args-default.c
CommitLineData
c1870f57 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
c1870f57 3 *
0235b0db
MJ
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
c1870f57
JG
6 */
7
c5d7b1f0
MJ
8#include <glib.h>
9
3fadfbc0 10#include <babeltrace2/babeltrace.h>
ec2c5e50
MJ
11#include "babeltrace2-cfg.h"
12#include "babeltrace2-cfg-cli-args.h"
13#include "babeltrace2-cfg-cli-args-default.h"
c1870f57
JG
14
15#ifdef BT_SET_DEFAULT_IN_TREE_CONFIGURATION
16
353c2524
SM
17enum bt_config_cli_args_status bt_config_cli_args_create_with_default(int argc,
18 const char *argv[], struct bt_config **cfg,
3dae1685 19 const bt_interrupter *interrupter)
c1870f57 20{
353c2524 21 enum bt_config_cli_args_status status;
b19ff26f 22 bt_value *initial_plugin_paths;
c1870f57
JG
23 int ret;
24
05e21286 25 initial_plugin_paths = bt_value_array_create();
290725f7
PP
26 if (!initial_plugin_paths) {
27 goto error;
28 }
29
30 ret = bt_config_append_plugin_paths(initial_plugin_paths,
5a3ee633 31 CONFIG_IN_TREE_PLUGIN_PATH);
290725f7
PP
32 if (ret) {
33 goto error;
34 }
35
afe821ca
MJ
36#ifdef CONFIG_IN_TREE_PROVIDER_DIR
37 /*
38 * Set LIBBABELTRACE2_PLUGIN_PROVIDER_DIR to load the in-tree Python
39 * plugin provider, if the env variable is already set, do not overwrite
40 * it.
41 */
c5d7b1f0 42 g_setenv("LIBBABELTRACE2_PLUGIN_PROVIDER_DIR", CONFIG_IN_TREE_PROVIDER_DIR, 0);
afe821ca
MJ
43#else
44 /*
45 * If the Pyhton plugin provider is disabled, use a non-exitent path to avoid
46 * loading the system installed provider if it exit, if the env variable is
47 * already set, do not overwrite it.
48 */
c5d7b1f0 49 g_setenv("LIBBABELTRACE2_PLUGIN_PROVIDER_DIR", "/nonexistent", 0);
afe821ca
MJ
50#endif
51
353c2524 52 status = bt_config_cli_args_create(argc, argv, cfg, true, true,
3dae1685 53 initial_plugin_paths, interrupter);
290725f7
PP
54 goto end;
55
56error:
353c2524 57 status = BT_CONFIG_CLI_ARGS_STATUS_ERROR;
290725f7
PP
58
59end:
c5b9b441 60 bt_value_put_ref(initial_plugin_paths);
353c2524 61 return status;
c1870f57
JG
62}
63
64#else /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */
65
353c2524
SM
66enum bt_config_cli_args_status bt_config_cli_args_create_with_default(int argc,
67 const char *argv[], struct bt_config **cfg,
3dae1685 68 const bt_interrupter *interrupter)
c1870f57 69{
353c2524 70 return bt_config_cli_args_create(argc, argv, cfg, false, false,
3dae1685 71 NULL, interrupter);
c1870f57
JG
72}
73
74#endif /* BT_SET_DEFAULT_IN_TREE_CONFIGURATION */
This page took 0.067695 seconds and 4 git commands to generate.