List available profiles in --list output

This commit is contained in:
Martin Lund 2024-05-03 11:29:28 +02:00
parent e9c96c5456
commit 31647a934c
4 changed files with 62 additions and 3 deletions

View file

@ -165,7 +165,7 @@ Default value is 200.
.TP .TP
.BR \-l ", " \-\-list .BR \-l ", " \-\-list
List available serial devices. List available targets (serial devices, TIDs, configuration profiles).
.TP .TP
.BR \-L ", " \-\-log .BR \-L ", " \-\-log
@ -173,7 +173,8 @@ List available serial devices.
Enable log to file. Enable log to file.
The log file will be automatically named using the following format The log file will be automatically named using the following format
tio_DEVICE_YYYY-MM-DDTHH:MM:SS.log. tio_TARGET_YYYY-MM-DDTHH:MM:SS.log. Target being the command line target such
as tty-device, tid, or configuration profile.
The filename can be manually set using the \-\-log-file option. The filename can be manually set using the \-\-log-file option.

View file

@ -603,3 +603,58 @@ void config_file_print(void)
} }
} }
} }
void config_list_targets(void)
{
memset(&config, 0, sizeof(struct config_t));
// Find config file
if (config_file_resolve() != 0)
{
// None found
return;
}
GKeyFile *keyfile;
GError *error = NULL;
keyfile = g_key_file_new();
if (!g_key_file_load_from_file(keyfile, config.path, G_KEY_FILE_NONE, &error))
{
tio_error_print("Failure loading file: %s", error->message);
g_error_free(error);
return;
}
// Get all group names
gsize num_groups;
gchar **group = g_key_file_get_groups(keyfile, &num_groups);
if (num_groups == 0)
{
return;
}
printf("\nConfiguration profiles\n");
printf("--------------------------------------------------------------------------------\n");
int j = 1;
for (gsize i = 0; i < num_groups; i++)
{
// Skip default group
if (strcmp(group[i], CONFIG_GROUP_NAME_DEFAULT) == 0)
{
continue;
}
printf("%-20s ", group[i]);
if (j++ % 4 == 0)
{
putchar('\n');
}
}
putchar('\n');
g_strfreev(group);
g_key_file_free(keyfile);
}

View file

@ -35,3 +35,4 @@ void config_file_print(void);
void config_file_parse(void); void config_file_parse(void);
void config_exit(void); void config_exit(void);
void config_file_show_profiles(void); void config_file_show_profiles(void);
void config_list_targets(void);

View file

@ -42,6 +42,7 @@
#include "alert.h" #include "alert.h"
#include "log.h" #include "log.h"
#include "script.h" #include "script.h"
#include "configfile.h"
#define HEX_N_VALUE_MAX 4096 #define HEX_N_VALUE_MAX 4096
@ -150,7 +151,7 @@ void option_print_help(char *argv[])
printf(" -t, --timestamp Enable line timestamp\n"); printf(" -t, --timestamp Enable line timestamp\n");
printf(" --timestamp-format <format> Set timestamp format (default: 24hour)\n"); printf(" --timestamp-format <format> Set timestamp format (default: 24hour)\n");
printf(" --timestamp-timeout <ms> Set timestamp timeout (default: 200)\n"); printf(" --timestamp-timeout <ms> Set timestamp timeout (default: 200)\n");
printf(" -l, --list List available serial devices\n"); printf(" -l, --list List available serial devices, TIDs, and profiles\n");
printf(" -L, --log Enable log to file\n"); printf(" -L, --log Enable log to file\n");
printf(" --log-file <filename> Set log filename\n"); printf(" --log-file <filename> Set log filename\n");
printf(" --log-directory <path> Set log directory path for automatic named logs\n"); printf(" --log-directory <path> Set log directory path for automatic named logs\n");
@ -916,6 +917,7 @@ void options_parse(int argc, char *argv[])
case 'l': case 'l':
list_serial_devices(); list_serial_devices();
config_list_targets();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
break; break;