Commit | Line | Data |
---|---|---|
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 | ||
31 | enum { | |
32 | OPT_HELP = 1, | |
33 | OPT_LIST_OPTIONS, | |
34 | }; | |
35 | ||
36 | static struct poptOption long_options[] = { | |
37 | /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ | |
38 | {"help", 'h', POPT_ARG_NONE, NULL, OPT_HELP, NULL, NULL}, | |
39 | {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, | |
40 | {0, 0, 0, 0, 0, 0, 0} | |
41 | }; | |
42 | ||
54a0adbf PP |
43 | static int status(void) |
44 | { | |
45 | const char *argv[2]; | |
46 | int ret = CMD_SUCCESS; | |
47 | char *session_name = NULL; | |
48 | ||
49 | session_name = get_session_name(); | |
50 | if (!session_name) { | |
51 | ret = CMD_ERROR; | |
52 | goto end; | |
53 | } | |
54 | ||
55 | argv[0] = "list"; | |
56 | argv[1] = session_name; | |
57 | ret = cmd_list(2, argv); | |
58 | end: | |
59 | free(session_name); | |
60 | return ret; | |
61 | } | |
62 | ||
63 | /* | |
64 | * The 'status <options>' first level command | |
65 | */ | |
66 | int cmd_status(int argc, const char **argv) | |
67 | { | |
68 | int opt, ret = CMD_SUCCESS; | |
69 | static poptContext pc; | |
70 | ||
71 | pc = poptGetContext(NULL, argc, argv, long_options, 0); | |
72 | poptReadDefaultConfig(pc, 0); | |
73 | ||
74 | while ((opt = poptGetNextOpt(pc)) != -1) { | |
75 | switch (opt) { | |
76 | case OPT_HELP: | |
4ba92f18 | 77 | SHOW_HELP(); |
54a0adbf PP |
78 | goto end; |
79 | case OPT_LIST_OPTIONS: | |
80 | list_cmd_options(stdout, long_options); | |
81 | goto end; | |
82 | default: | |
54a0adbf PP |
83 | ret = CMD_UNDEFINED; |
84 | goto end; | |
85 | } | |
86 | } | |
87 | ||
88 | if (poptPeekArg(pc) != NULL) { | |
89 | ERR("This command does not accept positional arguments.\n"); | |
54a0adbf PP |
90 | ret = CMD_UNDEFINED; |
91 | goto end; | |
92 | } | |
93 | ||
94 | ret = status(); | |
95 | end: | |
96 | poptFreeContext(pc); | |
97 | return ret; | |
98 | } |