Просмотр исходного кода

update-alternatives: add new option --get-selections

The new option list all master alternatives and their status
in a format simple to parse. It's also a practical way to know
the name of all available alternatives. Closes: #273406, #392429
Raphael Hertzog лет назад: 17
Родитель
Сommit
7a6e69f7b8
4 измененных файлов с 29 добавлено и 4 удалено
  1. 7 0
      ChangeLog
  2. 3 0
      debian/changelog
  3. 8 0
      man/update-alternatives.8
  4. 11 4
      scripts/update-alternatives.pl

+ 7 - 0
ChangeLog

@@ -1,3 +1,10 @@
+2009-02-22  Raphael Hertzog  <hertzog@debian.org>
+
+	* scripts/update-alternatives.pl: Implement --get-selections.
+	The new option lists all master alternatives and their status in a
+	format simple to parse.
+	* man/update-alternatives.8: Document this option.
+
 2009-02-22  Raphael Hertzog  <hertzog@debian.org>
 
 	* scripts/update-alternatives.pl: Installation of a slave

+ 3 - 0
debian/changelog

@@ -163,6 +163,9 @@ dpkg (1.15.0) UNRELEASED; urgency=low
     - new sanity checks on --install parameters. Closes: #423176
     - install slave link only if the corresponding slave file is available.
       Closes: #143701
+    - new option --get-selections to export the configuration of all
+      alternatives. It's a simple way to discover the name of all available
+      alternatives. Closes: #273406, #392429
 
   [ Pierre Habouzit ]
   * Add a --query option to update-alternatives. Closes: #336091, #441904

+ 8 - 0
man/update-alternatives.8

@@ -287,6 +287,14 @@ what other alternatives are available
 (and their corresponding slave alternatives),
 and the highest priority alternative currently installed.
 .TP
+\fB\-\-get\-selections\fR
+List all master alternative names (those controlling a link group)
+and their status. Each line contains up to 3 fields (separated by
+one or more spaces). The first field is the alternative name, the second
+one is the status (either "auto" or "manual"), and the last one contains
+the current choice in the alternative (beware: it's a filename and thus
+might contain spaces).
+.TP
 \fB\-\-query\fR \fIname\fR
 Display information about the link group
 like \-\-display does, but in a machine parseable way

+ 11 - 4
scripts/update-alternatives.pl

@@ -70,8 +70,8 @@ while (@ARGV) {
 	set_action($1);
         @ARGV || badusage(_g("--%s needs <name>"), $1);
         $alternative = Alternative->new(shift(@ARGV));
-    } elsif (m/^--all$/) {
-	set_action('all');
+    } elsif (m/^--(all|get-selections)$/) {
+	set_action($1);
     } elsif (m/^--slave$/) {
         badusage(_g("--slave only allowed with --install"))
             unless $action eq "install";
@@ -105,8 +105,9 @@ while (@ARGV) {
     }
 }
 
-badusage(_g("need --display, --query, --list, --config, --set, --install," .
-            "--remove, --all, --remove-all or --auto")) unless $action;
+badusage(_g("need --display, --query, --list, --get-selections, --config," .
+            "--set, --install, --remove, --all, --remove-all or --auto"))
+    unless $action;
 
 # Load infos about all alternatives to be able to check for mistakes
 my %ALL;
@@ -168,6 +169,12 @@ if ($action eq "install") {
 if ($action eq 'all') {
     config_all();
     exit 0;
+} elsif ($action eq 'get-selections') {
+    foreach my $alt_name (sort keys %{$ALL{objects}}) {
+        my $obj = $ALL{objects}{$alt_name};
+        printf "%-30s %-8s %s\n", $alt_name, $obj->status(), $obj->current() || "";
+    }
+    exit 0;
 }
 
 # Load the alternative info, stop on failure except for --install