diff --git a/Makefile-tests.am b/Makefile-tests.am
index 3323c5f3..9837e5cd 100644
--- a/Makefile-tests.am
+++ b/Makefile-tests.am
@@ -134,6 +134,7 @@ _installed_or_uninstalled_test_scripts = \
tests/test-repo-finder-mount-integration.sh \
tests/test-summary-collections.sh \
tests/test-pull-collections.sh \
+ tests/test-config.sh \
$(NULL)
experimental_test_scripts = \
diff --git a/bash/ostree b/bash/ostree
index d7b54373..677aee7c 100644
--- a/bash/ostree
+++ b/bash/ostree
@@ -398,6 +398,7 @@ _ostree_config() {
"
local options_with_args="
+ --group
--repo
"
diff --git a/man/ostree-config.xml b/man/ostree-config.xml
index f1232602..f052aebb 100644
--- a/man/ostree-config.xml
+++ b/man/ostree-config.xml
@@ -51,10 +51,10 @@ Boston, MA 02111-1307, USA.
- ostree config get SECTIONNAME.KEYNAME
+ ostree config get --group=GROUPNAME KEYNAME
- ostree config set SECTIONNAME.KEYNAME VALUE
+ ostree config set --group=GROUPNAME KEYNAME VALUE
@@ -68,7 +68,7 @@ Boston, MA 02111-1307, USA.
Example
- $ ostree config get core.mode
+ $ ostree config get --group=core mode
bare
diff --git a/src/ostree/ot-builtin-config.c b/src/ostree/ot-builtin-config.c
index 89bf3df9..b9fa824d 100644
--- a/src/ostree/ot-builtin-config.c
+++ b/src/ostree/ot-builtin-config.c
@@ -28,12 +28,15 @@
#include "ostree.h"
#include "otutil.h"
+static char* opt_group;
+
/* ATTENTION:
* Please remember to update the bash-completion script (bash/ostree) and
* man page (man/ostree-config.xml) when changing the option list.
*/
static GOptionEntry options[] = {
+ { "group", 0, 0, G_OPTION_ARG_STRING, &opt_group , "Group name followed by key for a remote config", NULL },
{ NULL }
};
@@ -44,7 +47,7 @@ split_key_string (const char *k,
GError **error)
{
const char *dot = strchr (k, '.');
-
+
if (!dot)
{
return glnx_throw (error,
@@ -85,18 +88,32 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
if (!strcmp (op, "set"))
{
- if (argc < 4)
+ printf("GROUP NUMBER = %s %d\n", opt_group, argc);
+ if (opt_group)
{
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "KEY and VALUE must be specified");
- goto out;
+ if (argc < 4)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "GROUP name, KEY and VALUE must be specified");
+ goto out;
+ }
+ section = g_strdup(opt_group);
+ key = g_strdup(argv[2]);
+ value = argv[3];
+ }
+ else
+ {
+ if (argc < 4)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "KEY and VALUE must be specified");
+ goto out;
+ }
+ section_key = argv[2];
+ value = argv[3];
+ if(!split_key_string (section_key, §ion, &key, error))
+ goto out;
}
-
- section_key = argv[2];
- value = argv[3];
-
- if (!split_key_string (section_key, §ion, &key, error))
- goto out;
config = ostree_repo_copy_config (repo);
g_key_file_set_string (config, section, key, value);
@@ -108,17 +125,29 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
{
GKeyFile *readonly_config = NULL;
g_autofree char *value = NULL;
- if (argc < 3)
+ if (opt_group)
{
- g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
- "KEY must be specified");
- goto out;
+ if (argc < 3)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "Group name and key must be specified");
+ goto out;
+ }
+ section = g_strdup(opt_group);
+ key = g_strdup(argv[2]);
+ }
+ else
+ {
+ if(argc < 3)
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+ "KEY must be specified");
+ goto out;
+ }
+ section_key = argv[2];
+ if (!split_key_string (section_key, §ion, &key, error))
+ goto out;
}
-
- section_key = argv[2];
-
- if (!split_key_string (section_key, §ion, &key, error))
- goto out;
readonly_config = ostree_repo_get_config (repo);
value = g_key_file_get_string (readonly_config, section, key, error);
@@ -133,7 +162,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
"Unknown operation %s", op);
goto out;
}
-
+
ret = TRUE;
out:
if (config)
diff --git a/tests/test-config.sh b/tests/test-config.sh
new file mode 100755
index 00000000..b1ea3e5e
--- /dev/null
+++ b/tests/test-config.sh
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# Copyright (C) 2018 Sinny Kumari
+#
+# SPDX-License-Identifier: LGPL-2.0+
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+set -euo pipefail
+
+. $(dirname $0)/libtest.sh
+
+echo '1..2'
+
+ostree_repo_init repo
+${CMD_PREFIX} ostree remote add --repo=repo --set=xa.title=Flathub --set=xa.title-is-set=true flathub https://dl.flathub.org/repo/
+${CMD_PREFIX} ostree remote add --repo=repo org.mozilla.FirefoxRepo http://example.com/ostree/repo/
+
+${CMD_PREFIX} ostree config --repo=repo get core.mode > list.txt
+${CMD_PREFIX} ostree config --repo=repo get --group=core repo_version >> list.txt
+${CMD_PREFIX} ostree config --repo=repo get --group='remote "flathub"' 'xa.title' >> list.txt
+${CMD_PREFIX} ostree config --repo=repo get --group='remote "flathub"' 'xa.title-is-set' >> list.txt
+${CMD_PREFIX} ostree config --repo=repo get --group='remote "org.mozilla.FirefoxRepo"' url >> list.txt
+${CMD_PREFIX} cat list.txt
+
+assert_file_has_content list.txt "bare"
+assert_file_has_content list.txt "1"
+assert_file_has_content list.txt "Flathub"
+assert_file_has_content list.txt "true"
+assert_file_has_content list.txt "http://example.com/ostree/repo/"
+echo "ok config get"
+
+${CMD_PREFIX} ostree config --repo=repo set core.mode bare-user-only
+${CMD_PREFIX} ostree config --repo=repo set --group='remote "flathub"' 'xa.title' 'Nightly Flathub'
+${CMD_PREFIX} ostree config --repo=repo set --group='remote "flathub"' 'xa.title-is-set' 'false'
+${CMD_PREFIX} ostree config --repo=repo set --group='remote "org.mozilla.FirefoxRepo"' url http://example.com/ostree/
+
+assert_file_has_content repo/config "bare-user-only"
+assert_file_has_content repo/config "Nightly Flathub"
+assert_file_has_content repo/config "false"
+assert_file_has_content repo/config "http://example.com/ostree/"
+echo "ok config set"