manager: honor --version option

Fixes #22
This commit is contained in:
Arnaud Ferraris
2021-10-05 23:08:33 +02:00
parent 68349c9f58
commit f68af6405d
2 changed files with 12 additions and 0 deletions

View File

@@ -46,6 +46,7 @@ eg25_datadir = join_paths(full_datadir, meson.project_name())
add_global_arguments('-D@0@="@1@"'.format('EG25_CONFDIR', eg25_confdir), language : 'c') add_global_arguments('-D@0@="@1@"'.format('EG25_CONFDIR', eg25_confdir), language : 'c')
add_global_arguments('-D@0@="@1@"'.format('EG25_DATADIR', eg25_datadir), language : 'c') add_global_arguments('-D@0@="@1@"'.format('EG25_DATADIR', eg25_datadir), language : 'c')
add_global_arguments('-D@0@="@1@"'.format('EG25_VERSION', meson.project_version()), language : 'c')
mmglib_dep = dependency('mm-glib', required : false) mmglib_dep = dependency('mm-glib', required : false)
if mmglib_dep.found() if mmglib_dep.found()

View File

@@ -34,6 +34,10 @@
#define EG25_DATADIR "/usr/share/eg25-manager" #define EG25_DATADIR "/usr/share/eg25-manager"
#endif #endif
#ifndef EG25_VERSION
#define EG25_VERSION "0.0.0"
#endif
#define POWERON_DELAY_US 100000UL #define POWERON_DELAY_US 100000UL
static gboolean quit_app(struct EG25Manager *manager) static gboolean quit_app(struct EG25Manager *manager)
@@ -286,10 +290,12 @@ int main(int argc, char *argv[])
g_autoptr(GError) err = NULL; g_autoptr(GError) err = NULL;
struct EG25Manager manager; struct EG25Manager manager;
gchar *config_file = NULL; gchar *config_file = NULL;
gboolean show_version = FALSE;
toml_table_t *toml_config[EG25_CONFIG_COUNT]; toml_table_t *toml_config[EG25_CONFIG_COUNT];
toml_table_t *manager_config[EG25_CONFIG_COUNT]; toml_table_t *manager_config[EG25_CONFIG_COUNT];
const GOptionEntry options[] = { const GOptionEntry options[] = {
{ "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file to use.", NULL }, { "config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Config file to use.", NULL },
{ "version", 'v', 0, G_OPTION_ARG_NONE, &show_version, "Display version information and exit.", NULL },
{ NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL } { NULL, 0, 0, G_OPTION_ARG_NONE, NULL, NULL, NULL }
}; };
@@ -306,6 +312,11 @@ int main(int argc, char *argv[])
return 1; return 1;
} }
if (show_version) {
printf("eg25-manager version %s\n", EG25_VERSION);
return 0;
}
manager.loop = g_main_loop_new(NULL, FALSE); manager.loop = g_main_loop_new(NULL, FALSE);
toml_config[EG25_CONFIG_SYS] = parse_config_file(NULL, TRUE); toml_config[EG25_CONFIG_SYS] = parse_config_file(NULL, TRUE);