mirror of
https://github.com/ostreedev/ostree.git
synced 2025-02-01 09:47:45 +03:00
show: Add --print-hex
The default GVariant output for byte arrays is illegible to humans, and byte arrays are super common for us.
This commit is contained in:
parent
6056ec130f
commit
eb01112083
@ -35,6 +35,7 @@ static gboolean opt_list_metadata_keys;
|
||||
static gboolean opt_list_detached_metadata_keys;
|
||||
static gboolean opt_print_sizes;
|
||||
static gboolean opt_raw;
|
||||
static gboolean opt_print_hex;
|
||||
static gboolean opt_no_byteswap;
|
||||
static char *opt_gpg_homedir;
|
||||
static char *opt_gpg_verify_remote;
|
||||
@ -53,6 +54,15 @@ static GOptionEntry options[]
|
||||
"List the available metadata keys", NULL },
|
||||
{ "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key,
|
||||
"Print string value of metadata key", "KEY" },
|
||||
{
|
||||
"print-hex",
|
||||
0,
|
||||
0,
|
||||
G_OPTION_ARG_NONE,
|
||||
&opt_print_hex,
|
||||
"For byte array valued keys, output an unquoted hexadecimal string",
|
||||
NULL,
|
||||
},
|
||||
{ "list-detached-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_detached_metadata_keys,
|
||||
"List the available detached metadata keys", NULL },
|
||||
{ "print-detached-metadata-key", 0, 0, G_OPTION_ARG_STRING,
|
||||
@ -186,6 +196,14 @@ do_print_metadata_key (OstreeRepo *repo, const char *resolved_rev, gboolean deta
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (opt_print_hex && g_variant_is_of_type (value, (GVariantType *)"ay"))
|
||||
{
|
||||
g_autofree char *buf = g_malloc (g_variant_get_size (value) * 2 + 1);
|
||||
ot_bin2hex (buf, g_variant_get_data (value), g_variant_get_size (value));
|
||||
g_print ("%s\n", buf);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (opt_no_byteswap)
|
||||
{
|
||||
g_autofree char *formatted = g_variant_print (value, TRUE);
|
||||
|
Loading…
x
Reference in New Issue
Block a user