Преглед изворни кода

dpkg-buildflags: Reverse exit logic to check for errors

Instead of defaulting to exiting with an error, and bailing out on
successful operations, reverse the logic as there are fewer error
exit codepaths. This also reduces code nesting.
Guillem Jover пре 12 година
родитељ
комит
794c651d09
1 измењених фајлова са 13 додато и 23 уклоњено
  1. 13 23
      scripts/dpkg-buildflags.pl

+ 13 - 23
scripts/dpkg-buildflags.pl

@@ -105,28 +105,23 @@ if ($action eq 'list') {
     foreach my $flag ($build_flags->list()) {
 	print "$flag\n";
     }
-    exit(0);
 } elsif ($action eq 'get') {
+    exit 1 unless $build_flags->has($param);
 
-    if ($build_flags->has($param)) {
-	print $build_flags->get($param) . "\n";
-	exit(0);
-    }
+    print $build_flags->get($param) . "\n";
 } elsif ($action eq 'origin') {
-    if ($build_flags->has($param)) {
-	print $build_flags->get_origin($param) . "\n";
-	exit(0);
-    }
+    exit 1 unless $build_flags->has($param);
+
+    print $build_flags->get_origin($param) . "\n";
 } elsif ($action eq 'query-features') {
-    if ($build_flags->has_features($param)) {
-	my %features = $build_flags->get_features($param);
-	my $para_shown = 0;
-	foreach my $feature (sort keys %features) {
-	    print $para_shown++ ? "\n" : '';
-	    printf "Feature: %s\n", $feature;
-	    printf "Enabled: %s\n", $features{$feature} ? 'yes' : 'no';
-	}
-	exit(0);
+    exit 1 unless $build_flags->has_features($param);
+
+    my %features = $build_flags->get_features($param);
+    my $para_shown = 0;
+    foreach my $feature (sort keys %features) {
+        print $para_shown++ ? "\n" : '';
+        printf "Feature: %s\n", $feature;
+        printf "Enabled: %s\n", $features{$feature} ? 'yes' : 'no';
     }
 } elsif ($action =~ m/^export-(.*)$/) {
     my $export_type = $1;
@@ -143,13 +138,11 @@ if ($action eq 'list') {
 	    print "$flag=\"$value\" ";
 	}
     }
-    exit(0);
 } elsif ($action eq 'dump') {
     foreach my $flag ($build_flags->list()) {
 	my $value = $build_flags->get($flag);
 	print "$flag=$value\n";
     }
-    exit(0);
 } elsif ($action eq 'status') {
     # Prefix everything with "dpkg-buildflags: status: " to allow easy
     # extraction from a build log. Thus we use report with a non-translated
@@ -183,7 +176,4 @@ if ($action eq 'list') {
 	my $maintainer = $build_flags->is_maintainer_modified($flag) ? '+maintainer' : '';
 	print report('status', "$flag [$origin$maintainer]: $value");
     }
-    exit(0);
 }
-
-exit(1);