21 bump_verbosity(
const gchar *option_name,
const gchar *optarg, gpointer
data, GError **error) {
37 args->
summary = strdup(summary);
48 free_common_args(gpointer
data) {
64 GOptionGroup **output_group,
const char *param_string) {
66 GOptionContext *context;
67 GOptionGroup *main_group;
69 GOptionEntry main_entries[3] = {
70 {
"version",
'$', 0, G_OPTION_ARG_NONE, &(common_args->
version),
71 "Display software version and exit",
73 {
"verbose",
'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, bump_verbosity,
74 "Increase debug output (may be specified multiple times)",
80 main_group = g_option_group_new(NULL,
"Application Options:", NULL, common_args, free_common_args);
81 g_option_group_add_entries(main_group, main_entries);
83 context = g_option_context_new(param_string);
84 g_option_context_set_summary(context, common_args->
summary);
85 g_option_context_set_description(context, desc);
86 g_option_context_set_main_group(context, main_group);
89 GOptionEntry output_entries[3] = {
90 {
"output-as", 0, 0, G_OPTION_ARG_STRING, &(common_args->
output_ty),
93 {
"output-to", 0, 0, G_OPTION_ARG_STRING, &(common_args->
output_dest),
94 "Specify file name for output (or \"-\" for stdout)",
"DEST" },
99 if (*output_group == NULL) {
100 *output_group = g_option_group_new(
"output",
"Output Options:",
"Show output help", NULL, NULL);
105 g_option_group_add_entries(*output_group, output_entries);
106 g_option_context_add_group(context, *output_group);
118 if (context == NULL) {
122 g_option_context_free(context);
128 GOptionGroup *main_group = g_option_context_get_main_group(context);
130 g_option_group_add_entries(main_group, entries);
135 const char *header,
const char *desc,
136 GOptionEntry entries[])
138 GOptionGroup *group = NULL;
140 group = g_option_group_new(
name, header, desc, NULL, NULL);
141 g_option_group_add_entries(group, entries);
142 g_option_context_add_group(context, group);
149 GPtrArray *arr = NULL;
150 bool saw_dash_dash =
false;
151 bool copy_option =
false;
157 if (g_get_prgname() == NULL && argv && *argv) {
158 gchar *basename = g_path_get_basename(*argv);
160 g_set_prgname(basename);
164 arr = g_ptr_array_new();
166 for (
int i = 0; argv[i] != NULL; i++) {
172 if (saw_dash_dash ==
false && strcmp(argv[i],
"--") == 0) {
173 saw_dash_dash =
true;
176 if (saw_dash_dash ==
true) {
177 g_ptr_array_add(arr, g_strdup(argv[i]));
181 if (copy_option ==
true) {
182 g_ptr_array_add(arr, g_strdup(argv[i]));
191 g_ptr_array_add(arr, g_strdup(argv[i]));
198 if (g_str_has_prefix(argv[i],
"-") && !g_str_has_prefix(argv[i],
"--")) {
200 char *ch = argv[i]+1;
207 if (*ch !=
'\0' && *ch >=
'1' && *ch <=
'9') {
208 bool is_numeric =
true;
210 while (*ch !=
'\0') {
220 g_ptr_array_add(arr, g_strdup_printf(
"%s", argv[i]));
230 while (*ch !=
'\0') {
236 if (special != NULL && strchr(special, *ch) != NULL) {
240 if (*(ch+1) !=
'\0') {
241 g_ptr_array_add(arr, g_strdup_printf(
"-%c", *ch));
242 g_ptr_array_add(arr, g_strdup(ch+1));
250 g_ptr_array_add(arr, g_strdup_printf(
"-%c", *ch));
257 g_ptr_array_add(arr, g_strdup_printf(
"-%c", *ch));
267 g_ptr_array_add(arr, g_strdup(argv[i]));
271 g_ptr_array_add(arr, NULL);
273 return (
char **) g_ptr_array_free(arr, FALSE);
281 gchar **extra_args = NULL;
283 gboolean retval = TRUE;
285 va_start(ap, format);
286 len = vasprintf(&buf, format, ap);
290 if (!g_shell_parse_argv(buf, NULL, &extra_args, error)) {
291 g_strfreev(extra_args);
296 retval = g_option_context_parse_strv(context, &extra_args, error);
298 g_strfreev(extra_args);
gchar ** pcmk__cmdline_preproc(char **argv, const char *special)
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
void pcmk__add_arg_group(GOptionContext *context, const char *name, const char *header, const char *desc, GOptionEntry entries[])
GOptionContext * pcmk__build_arg_context(pcmk__common_args_t *common_args, const char *fmts, GOptionGroup **output_group, const char *param_string)
External (OS/environmental) problem.
pcmk__common_args_t * pcmk__new_common_args(const char *summary)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
void pcmk__free_arg_context(GOptionContext *context)
gboolean pcmk__force_args(GOptionContext *context, GError **error, const char *format,...)
#define PACKAGE_BUGREPORT
void pcmk__add_main_args(GOptionContext *context, GOptionEntry entries[])