cmdline: (cleanup) Add internal helper to parse key=value options
This will be used by a later "ostree admin set-origin" as well.
This commit is contained in:
parent
0eac91a253
commit
1d216a8c60
|
|
@ -25,6 +25,7 @@
|
||||||
#include "ot-main.h"
|
#include "ot-main.h"
|
||||||
#include "ot-builtins.h"
|
#include "ot-builtins.h"
|
||||||
#include "ostree.h"
|
#include "ostree.h"
|
||||||
|
#include "ot-tool-util.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -35,24 +36,6 @@ usage_error (GOptionContext *context, const char *message, GError **error)
|
||||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, message);
|
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
|
||||||
parse_keyvalue (const char *keyvalue,
|
|
||||||
char **out_key,
|
|
||||||
char **out_value,
|
|
||||||
GError **error)
|
|
||||||
{
|
|
||||||
const char *eq = strchr (keyvalue, '=');
|
|
||||||
if (!eq)
|
|
||||||
{
|
|
||||||
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
|
||||||
"Missing '=' in KEY=VALUE for --set");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
*out_key = g_strndup (keyvalue, eq - keyvalue);
|
|
||||||
*out_value = g_strdup (eq + 1);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char **opt_set;
|
static char **opt_set;
|
||||||
static gboolean opt_no_gpg_verify;
|
static gboolean opt_no_gpg_verify;
|
||||||
static gboolean opt_if_not_exists;
|
static gboolean opt_if_not_exists;
|
||||||
|
|
@ -114,7 +97,7 @@ ostree_remote_builtin_add (int argc, char **argv, GCancellable *cancellable, GEr
|
||||||
gs_free char *subkey = NULL;
|
gs_free char *subkey = NULL;
|
||||||
gs_free char *subvalue = NULL;
|
gs_free char *subvalue = NULL;
|
||||||
|
|
||||||
if (!parse_keyvalue (keyvalue, &subkey, &subvalue, error))
|
if (!ot_parse_keyvalue (keyvalue, &subkey, &subvalue, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
g_variant_builder_add (optbuilder, "{s@v}",
|
g_variant_builder_add (optbuilder, "{s@v}",
|
||||||
|
|
|
||||||
|
|
@ -51,3 +51,21 @@ ot_parse_boolean (const char *option_name,
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
ot_parse_keyvalue (const char *keyvalue,
|
||||||
|
char **out_key,
|
||||||
|
char **out_value,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
const char *eq = strchr (keyvalue, '=');
|
||||||
|
if (!eq)
|
||||||
|
{
|
||||||
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||||
|
"Missing '=' in KEY=VALUE for --set");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
*out_key = g_strndup (keyvalue, eq - keyvalue);
|
||||||
|
*out_value = g_strdup (eq + 1);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,11 @@ ot_parse_boolean (const char *option_name,
|
||||||
const char *value,
|
const char *value,
|
||||||
gboolean *out_parsed,
|
gboolean *out_parsed,
|
||||||
GError **error);
|
GError **error);
|
||||||
|
gboolean
|
||||||
|
ot_parse_keyvalue (const char *keyvalue,
|
||||||
|
char **out_key,
|
||||||
|
char **out_value,
|
||||||
|
GError **error);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue