refactor: add shell version to command line option
This commit is contained in:
@ -12,6 +12,7 @@ add_project_arguments(
|
||||
'-Wno-pedantic',
|
||||
'-Werror=implicit-function-declaration',
|
||||
'-Werror=return-type',
|
||||
'-D__SHELL_VERSION__="@0@"'.format(meson.project_version())
|
||||
],
|
||||
language: 'c')
|
||||
|
||||
|
32
src/shell.c
32
src/shell.c
@ -423,6 +423,21 @@ static void diya_shell_class_init(DiyaShellClass *class)
|
||||
G_TYPE_UINT);
|
||||
}
|
||||
|
||||
static int diya_shell_handle_local_options(GApplication *application, GVariantDict *options, gpointer user_data)
|
||||
{
|
||||
(void) application;
|
||||
(void) user_data;
|
||||
#ifdef __SHELL_VERSION__
|
||||
guint32 count;
|
||||
if (g_variant_dict_lookup(options, "version", "b", &count))
|
||||
{
|
||||
g_print("Shell version: %s\n", __SHELL_VERSION__);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int diya_shell_run(DiyaShell *shell, int argc, char **argv)
|
||||
{
|
||||
DiyaShellPrivate *priv = diya_shell_get_instance_private(shell);
|
||||
@ -440,7 +455,22 @@ int diya_shell_run(DiyaShell *shell, int argc, char **argv)
|
||||
gchar *path = g_strconcat(g_get_user_config_dir(), "/diya/xkb/", NULL);
|
||||
g_mkdir_with_parents((const gchar *)path, 0755);
|
||||
g_free(path);
|
||||
|
||||
const GOptionEntry cmd_params[] =
|
||||
{
|
||||
#ifdef __SHELL_VERSION__
|
||||
{
|
||||
.long_name = "version",
|
||||
.short_name = 'v',
|
||||
.flags = G_OPTION_FLAG_NONE,
|
||||
.arg = G_OPTION_ARG_NONE,
|
||||
.arg_data = NULL,
|
||||
.description = "Show version information",
|
||||
.arg_description = NULL,
|
||||
},
|
||||
#endif
|
||||
{NULL}};
|
||||
g_application_add_main_option_entries(G_APPLICATION(app), cmd_params);
|
||||
g_signal_connect(app, "handle-local-options", G_CALLBACK(diya_shell_handle_local_options), shell);
|
||||
int status = g_application_run(G_APPLICATION(app), argc, argv);
|
||||
g_object_unref(app);
|
||||
return status;
|
||||
|
Reference in New Issue
Block a user