20 bump_verbosity(
const gchar *option_name,
const gchar *optarg, gpointer
data, GError **error) {
36 args->
summary = strdup(summary);
45 free_common_args(gpointer
data) {
61 GOptionGroup **output_group,
const char *param_string) {
63 GOptionContext *context;
64 GOptionGroup *main_group;
66 GOptionEntry main_entries[3] = {
67 {
"version",
'$', 0, G_OPTION_ARG_NONE, &(common_args->
version),
68 "Display software version and exit",
70 {
"verbose",
'V', G_OPTION_FLAG_NO_ARG, G_OPTION_ARG_CALLBACK, bump_verbosity,
71 "Increase debug output (may be specified multiple times)",
77 main_group = g_option_group_new(NULL,
"Application Options:", NULL, common_args, free_common_args);
78 g_option_group_add_entries(main_group, main_entries);
80 context = g_option_context_new(param_string);
81 g_option_context_set_summary(context, common_args->
summary);
82 g_option_context_set_description(context, desc);
83 g_option_context_set_main_group(context, main_group);
86 GOptionEntry output_entries[3] = {
87 {
"output-as", 0, 0, G_OPTION_ARG_STRING, &(common_args->
output_ty),
90 {
"output-to", 0, 0, G_OPTION_ARG_STRING, &(common_args->
output_dest),
91 "Specify file name for output (or \"-\" for stdout)",
"DEST" },
96 if (*output_group == NULL) {
97 *output_group = g_option_group_new(
"output",
"Output Options:",
"Show output help", NULL, NULL);
102 g_option_group_add_entries(*output_group, output_entries);
103 g_option_context_add_group(context, *output_group);
115 if (context == NULL) {
119 g_option_context_free(context);
125 GOptionGroup *main_group = g_option_context_get_main_group(context);
127 g_option_group_add_entries(main_group, entries);
132 const char *header,
const char *desc,
133 GOptionEntry entries[])
135 GOptionGroup *group = NULL;
137 group = g_option_group_new(name, header, desc, NULL, NULL);
138 g_option_group_add_entries(group, entries);
139 g_option_context_add_group(context, group);
146 GPtrArray *arr = NULL;
147 bool saw_dash_dash =
false;
153 if (g_get_prgname() == NULL && argv && *argv) {
154 gchar *basename = g_path_get_basename(*argv);
156 g_set_prgname(basename);
160 arr = g_ptr_array_new();
162 for (
int i = 0; argv[i] != NULL; i++) {
168 if (saw_dash_dash ==
false && strcmp(argv[i],
"--") == 0) {
169 saw_dash_dash =
true;
172 if (saw_dash_dash ==
true) {
173 g_ptr_array_add(arr, g_strdup(argv[i]));
181 g_ptr_array_add(arr, g_strdup(argv[i]));
188 if (g_str_has_prefix(argv[i],
"-") && !g_str_has_prefix(argv[i],
"--")) {
190 char *ch = argv[i]+1;
192 while (*ch !=
'\0') {
198 if (special != NULL && strchr(special, *ch) != NULL) {
202 if (*(ch+1) !=
'\0') {
203 g_ptr_array_add(arr, g_strdup_printf(
"-%c", *ch));
204 g_ptr_array_add(arr, g_strdup(ch+1));
212 g_ptr_array_add(arr, g_strdup_printf(
"-%c", *ch));
218 g_ptr_array_add(arr, g_strdup_printf(
"-%c", *ch));
228 g_ptr_array_add(arr, g_strdup(argv[i]));
232 g_ptr_array_add(arr, NULL);
234 return (
char **) g_ptr_array_free(arr, FALSE);
242 gchar **extra_args = NULL;
244 gboolean retval = TRUE;
246 va_start(ap, format);
247 len = vasprintf(&buf, format, ap);
251 if (!g_shell_parse_argv(buf, NULL, &extra_args, error)) {
252 g_strfreev(extra_args);
257 retval = g_option_context_parse_strv(context, &extra_args, error);
259 g_strfreev(extra_args);
crm_exit_t crm_errno2exit(int rc)
pcmk__common_args_t * pcmk__new_common_args(const char *summary)
gchar ** pcmk__cmdline_preproc(char **argv, const char *special)
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
gboolean summary(GList *resources)
GOptionContext * pcmk__build_arg_context(pcmk__common_args_t *common_args, const char *fmts, GOptionGroup **output_group, const char *param_string)
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,...)
void pcmk__add_arg_group(GOptionContext *context, const char *name, const char *header, const char *desc, GOptionEntry entries[])
void pcmk__add_main_args(GOptionContext *context, GOptionEntry entries[])
#define PACKAGE_BUGREPORT