7 handle_local_options (GApplication
*application
,
13 /* Deal (locally) with version option */
14 if (g_variant_dict_lookup (options
, "version", "b", &count
))
16 g_print ("This is example-cmdline4, version 1.2.3\n");
25 command_line (GApplication
*application
,
26 GApplicationCommandLine
*cmdline
,
31 GVariantDict
*options
= g_application_command_line_get_options_dict (cmdline
);
33 /* Deal with arg option */
34 if (g_variant_dict_lookup (options
, "flag", "b", &count
))
36 g_application_command_line_print (cmdline
, "flag is set\n");
44 main (int argc
, char **argv
)
49 GOptionEntry entries
[] = {
50 /* A version flag option, to be handled locally */
51 { "version", 'v', G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, NULL
, "Show the application version", NULL
},
53 /* A dummy flag option, to be handled in primary */
54 { "flag", 'f', G_OPTION_FLAG_NONE
, G_OPTION_ARG_NONE
, NULL
, "A flag argument", NULL
},
59 app
= g_application_new ("org.gtk.TestApplication",
60 G_APPLICATION_HANDLES_COMMAND_LINE
);
62 g_application_add_main_option_entries (app
, entries
);
64 g_application_set_option_context_parameter_string (app
, "- a simple command line example");
65 g_application_set_option_context_summary (app
,
67 "This is a simple command line --help example.");
68 g_application_set_option_context_description (app
,
70 "This example illustrates the use of "
71 "g_application command line --help functionalities "
72 "(parameter string, summary, description). "
73 "It does nothing at all except displaying information "
74 "when invoked with --help argument...\n");
76 g_signal_connect (app
, "handle-local-options", G_CALLBACK (handle_local_options
), NULL
);
77 g_signal_connect (app
, "command-line", G_CALLBACK (command_line
), NULL
);
79 /* This application does absolutely nothing, except if a command line is given */
80 status
= g_application_run (app
, argc
, argv
);