diff options
author | Colin Walters <walters@verbum.org> | 2013-09-28 12:00:16 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-09-28 12:00:16 -0400 |
commit | 0f486105db56e16302a9298ae68449ef07461459 (patch) | |
tree | 8827f39e160ba8bdb5a7efba4d9719f06de91e37 /src/ostree/ot-builtin-remote.c | |
parent | 38a5f6e5ed61cfb7a831c78920a8d11457c59dee (diff) | |
download | ostree-0f486105db56e16302a9298ae68449ef07461459.tar.gz |
remote-add: Add --set=KEY=VALUE option
This can be used to add a remote and set e.g. tls-permissive=true, or
gpgverify=false.
Diffstat (limited to 'src/ostree/ot-builtin-remote.c')
-rw-r--r-- | src/ostree/ot-builtin-remote.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c index 98a8b4b3..1f72883a 100644 --- a/src/ostree/ot-builtin-remote.c +++ b/src/ostree/ot-builtin-remote.c @@ -26,7 +26,10 @@ #include "ostree.h" #include "otutil.h" +char **opt_set; + static GOptionEntry options[] = { + { "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, "Set config option KEY=VALUE for remote", "KEY=VALUE" }, { NULL } }; @@ -40,6 +43,24 @@ usage_error (GOptionContext *context, const char *message, GError **error) 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; +} + gboolean ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error) { @@ -69,6 +90,7 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca if (!strcmp (op, "add")) { char *key; + char **iter; if (argc < 4) { usage_error (context, "NAME and URL must be specified", error); @@ -81,6 +103,19 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca key = g_strdup_printf ("remote \"%s\"", argv[2]); g_key_file_set_string (config, key, "url", argv[3]); + + for (iter = opt_set; iter && *iter; iter++) + { + const char *keyvalue = *iter; + gs_free char *subkey = NULL; + gs_free char *subvalue = NULL; + + if (!parse_keyvalue (keyvalue, &subkey, &subvalue, error)) + goto out; + + g_key_file_set_string (config, key, subkey, subvalue); + } + if (branches->len > 0) g_key_file_set_string_list (config, key, "branches", (const char *const *)branches->pdata, |