[ostree] main/remote: Add a show-url operation to the remote command
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] main/remote: Add a show-url operation to the remote command
- Date: Mon, 28 Oct 2013 13:14:57 +0000 (UTC)
commit 03aa10f17d54fac00f24facd2e7bfeb7c347584d
Author: Daniel Narvaez <dwnarvaez gmail com>
Date: Sun Oct 27 18:20:12 2013 +0100
main/remote: Add a show-url operation to the remote command
Useful to get the remote url in scripts.
https://bugzilla.gnome.org/show_bug.cgi?id=710967
src/ostree/ot-builtin-remote.c | 26 ++++++++++++++++++++------
tests/test-basic.sh | 5 +++++
2 files changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c
index 1f72883..495b27e 100644
--- a/src/ostree/ot-builtin-remote.c
+++ b/src/ostree/ot-builtin-remote.c
@@ -67,33 +67,38 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
GOptionContext *context;
gboolean ret = FALSE;
const char *op;
+ gs_free char *key = NULL;
guint i;
gs_unref_ptrarray GPtrArray *branches = NULL;
GKeyFile *config = NULL;
- context = g_option_context_new ("OPERATION [args] - Control remote repository configuration");
+ context = g_option_context_new ("OPERATION NAME [args] - Control remote repository configuration");
g_option_context_add_main_entries (context, options, NULL);
if (!g_option_context_parse (context, &argc, &argv, error))
goto out;
- if (argc < 2)
+ if (argc < 3)
{
- usage_error (context, "OPERATION must be specified", error);
+ if (argc == 1)
+ usage_error (context, "OPERATION must be specified", error);
+ else
+ usage_error (context, "NAME must be specified", error);
+
goto out;
}
op = argv[1];
+ key = g_strdup_printf ("remote \"%s\"", argv[2]);
config = ostree_repo_copy_config (repo);
if (!strcmp (op, "add"))
{
- char *key;
char **iter;
if (argc < 4)
{
- usage_error (context, "NAME and URL must be specified", error);
+ usage_error (context, "URL must be specified", error);
goto out;
}
@@ -101,7 +106,6 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
for (i = 4; i < argc; i++)
g_ptr_array_add (branches, argv[i]);
- 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++)
@@ -122,6 +126,16 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
branches->len);
g_free (key);
}
+ else if (!strcmp (op, "show-url"))
+ {
+ gs_free char *url;
+
+ url = g_key_file_get_string (config, key, "url", error);
+ if (url == NULL)
+ goto out;
+
+ g_print ("%s\n", url);
+ }
else
{
usage_error (context, "Unknown operation", error);
diff --git a/tests/test-basic.sh b/tests/test-basic.sh
index 8c32b09..dd6103b 100755
--- a/tests/test-basic.sh
+++ b/tests/test-basic.sh
@@ -305,3 +305,8 @@ assert_file_has_content repo/config 'tls-permissive=true'
assert_file_has_content repo/config 'remote\.example\.com'
echo "ok remote add with set"
+cd ${test_tmpdir}
+${CMD_PREFIX} ostree --repo=repo remote show-url aremote > aremote-url.txt
+assert_file_has_content aremote-url.txt 'http.*remote\.example\.com/repo'
+echo "ok remote show-url"
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]