[dconf] Add 'dconf reset'.



commit 8a7c838d9d574dfe16722154ff7e5842cae795e1
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon May 9 14:42:33 2011 +0200

    Add 'dconf reset'.

 bin/dconf-bash-completion.sh |   14 +++++++++++---
 bin/dconf.vala               |   28 ++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 3 deletions(-)
---
diff --git a/bin/dconf-bash-completion.sh b/bin/dconf-bash-completion.sh
index fc1e7aa..46d732d 100644
--- a/bin/dconf-bash-completion.sh
+++ b/bin/dconf-bash-completion.sh
@@ -9,22 +9,30 @@ __dconf() {
 
   case "${COMP_CWORD}" in
     1)
-      choices=$'help \nread \nlist \nwrite \nupdate \nlock \nunlock \nwatch '
+      choices=$'help \nread \nlist \nwrite \nreset\n update \nlock \nunlock \nwatch '
       ;;
 
     2)
       case "${COMP_WORDS[1]}" in
         help)
-          choices=$'help \nread \nlist \nwrite \nupdate \nlock \nunlock \nwatch '
+          choices=$'help \nread \nlist \nwrite \nreset\n update \nlock \nunlock \nwatch '
           ;;
         list)
           choices="$(dconf _complete / "${COMP_WORDS[2]}")"
           ;;
-        read|list|write|lock|unlock|watch)
+        read|list|write|lock|unlock|watch|reset)
           choices="$(dconf _complete '' "${COMP_WORDS[2]}")"
           ;;
       esac
       ;;
+
+    3)
+      case "${COMP_WORDS[1]} ${COMP_WORDS[2]}" in
+	reset\ -f)
+          choices="$(dconf _complete '' "${COMP_WORDS[3]}")"
+          ;;
+      esac
+      ;;
   esac
 
   local IFS=$'\n'
diff --git a/bin/dconf.vala b/bin/dconf.vala
index b6dc649..a2d7a60 100644
--- a/bin/dconf.vala
+++ b/bin/dconf.vala
@@ -49,6 +49,11 @@ void show_help (bool requested, string? command) {
 			synopsis = "KEY VALUE";
 			break;
 
+		case "reset":
+			description = "Reset a key or dir.  -f is required for dirs.";
+			synopsis = "[-f] PATH";
+			break;
+
 		case "update":
 			description = "Update the system dconf databases";
 			synopsis = "";
@@ -85,6 +90,7 @@ Commands:
   read              Read the value of a key
   list              List the contents of a dir
   write             Change the value of a key
+  reset             Reset the value of a key or dir
   update            Update the system databases
   lock              Set a lock on a path
   unlock            Clear a lock on a path
@@ -170,6 +176,27 @@ void dconf_write (string?[] args) throws Error {
 	client.write (key, Variant.parse (null, val));
 }
 
+void dconf_reset (string?[] args) throws Error {
+	var client = new DConf.Client ();
+	bool force = false;
+	var index = 2;
+
+	if (args[index] == "-f") {
+		force = true;
+		index++;
+	}
+
+	var path = args[index];
+
+	DConf.verify_path (path);
+
+	if (DConf.is_dir (path) && !force) {
+		throw new OptionError.FAILED ("-f must be given to (recursively) reset entire dirs");
+	}
+
+	client.write (path, null);
+}
+
 void dconf_lock (string?[] args) throws Error {
 	var client = new DConf.Client ();
 	var key = args[2];
@@ -249,6 +276,7 @@ int main (string[] args) {
 		CommandMapping ("read",      dconf_read),
 		CommandMapping ("list",      dconf_list),
 		CommandMapping ("write",     dconf_write),
+		CommandMapping ("reset",     dconf_reset),
 		CommandMapping ("update",    dconf_update),
 		CommandMapping ("lock",      dconf_lock),
 		CommandMapping ("unlock",    dconf_unlock),



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]