Add --enable-embedded-help option to embed --help messages in binaries
[lttng-tools.git] / src / bin / lttng / commands / status.c
CommitLineData
54a0adbf
PP
1/*
2 * Copyright (C) 2015 - Philippe Proulx <pproulx@efficios.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
54a0adbf
PP
18#define _LGPL_SOURCE
19#include <popt.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <unistd.h>
26
27#include "../command.h"
28#include "../utils.h"
29#include <config.h>
30
4fc83d94
PP
31#ifdef LTTNG_EMBED_HELP
32static const char help_msg[] =
33#include <lttng-status.1.h>
34;
35#endif
36
54a0adbf
PP
37enum {
38 OPT_HELP = 1,
39 OPT_LIST_OPTIONS,
40};
41
42static struct poptOption long_options[] = {
43 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
44 {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL},
45 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
46 {0, 0, 0, 0, 0, 0, 0}
47};
48
54a0adbf
PP
49static int status(void)
50{
51 const char *argv[2];
52 int ret = CMD_SUCCESS;
53 char *session_name = NULL;
54
55 session_name = get_session_name();
56 if (!session_name) {
57 ret = CMD_ERROR;
58 goto end;
59 }
60
61 argv[0] = "list";
62 argv[1] = session_name;
63 ret = cmd_list(2, argv);
64end:
65 free(session_name);
66 return ret;
67}
68
69/*
70 * The 'status <options>' first level command
71 */
72int cmd_status(int argc, const char **argv)
73{
74 int opt, ret = CMD_SUCCESS;
75 static poptContext pc;
76
77 pc = poptGetContext(NULL, argc, argv, long_options, 0);
78 poptReadDefaultConfig(pc, 0);
79
80 while ((opt = poptGetNextOpt(pc)) != -1) {
81 switch (opt) {
82 case OPT_HELP:
4ba92f18 83 SHOW_HELP();
54a0adbf
PP
84 goto end;
85 case OPT_LIST_OPTIONS:
86 list_cmd_options(stdout, long_options);
87 goto end;
88 default:
54a0adbf
PP
89 ret = CMD_UNDEFINED;
90 goto end;
91 }
92 }
93
94 if (poptPeekArg(pc) != NULL) {
95 ERR("This command does not accept positional arguments.\n");
54a0adbf
PP
96 ret = CMD_UNDEFINED;
97 goto end;
98 }
99
100 ret = status();
101end:
102 poptFreeContext(pc);
103 return ret;
104}
This page took 0.033124 seconds and 5 git commands to generate.