cli: add helper methods for implementing NmcMetaGenericInfo's get_fcn()

This commit is contained in:
Thomas Haller 2018-04-27 11:26:47 +02:00
parent 69d5fc9bce
commit 5975e4a39e
2 changed files with 41 additions and 0 deletions

View file

@ -165,6 +165,46 @@ struct _NmcMetaGenericInfo {
NULL, \
}))
static inline const char *
nmc_meta_generic_get_str_i18n (const char *s, NMMetaAccessorGetType get_type)
{
if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY,
NM_META_ACCESSOR_GET_TYPE_PARSABLE))
g_return_val_if_reached (NULL);
if (!s)
return NULL;
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return gettext (s);
return s;
}
static inline const char *
nmc_meta_generic_get_bool (gboolean val, NMMetaAccessorGetType get_type)
{
return nmc_meta_generic_get_str_i18n (val ? N_("yes") : N_("no"), get_type);
}
static inline char *
nmc_meta_generic_get_enum_with_detail (gint64 enum_val, const char *str_val, NMMetaAccessorGetType get_type)
{
if (!NM_IN_SET (get_type, NM_META_ACCESSOR_GET_TYPE_PRETTY,
NM_META_ACCESSOR_GET_TYPE_PARSABLE))
g_return_val_if_reached (NULL);
if (!str_val) {
/* Pass %NULL for only printing the numeric value. */
return g_strdup_printf ("%lld", (long long) enum_val);
}
/* note that this function will always print "$NUM ($NICK)", also in PARSABLE
* mode. That might not be desired, but it's done for certain properties to preserve
* previous behavior. */
if (get_type == NM_META_ACCESSOR_GET_TYPE_PRETTY)
return g_strdup_printf (_("%lld (%s)"), (long long) enum_val, gettext (str_val));
return g_strdup_printf ("%lld (%s)", (long long) enum_val, str_val);
}
/*****************************************************************************/
gboolean nmc_print (const NmcConfig *nmc_config,

View file

@ -10,6 +10,7 @@ clients/cli/nmcli.c
clients/cli/polkit-agent.c
clients/cli/settings.c
clients/cli/utils.c
clients/cli/utils.h
clients/common/nm-client-utils.c
clients/common/nm-meta-setting-access.c
clients/common/nm-meta-setting-desc.c