瀏覽代碼

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 11 年之前
父節點
當前提交
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()) {
     foreach my $flag ($build_flags->list()) {
 	print "$flag\n";
 	print "$flag\n";
     }
     }
-    exit(0);
 } elsif ($action eq 'get') {
 } 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') {
 } 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') {
 } 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-(.*)$/) {
 } elsif ($action =~ m/^export-(.*)$/) {
     my $export_type = $1;
     my $export_type = $1;
@@ -143,13 +138,11 @@ if ($action eq 'list') {
 	    print "$flag=\"$value\" ";
 	    print "$flag=\"$value\" ";
 	}
 	}
     }
     }
-    exit(0);
 } elsif ($action eq 'dump') {
 } elsif ($action eq 'dump') {
     foreach my $flag ($build_flags->list()) {
     foreach my $flag ($build_flags->list()) {
 	my $value = $build_flags->get($flag);
 	my $value = $build_flags->get($flag);
 	print "$flag=$value\n";
 	print "$flag=$value\n";
     }
     }
-    exit(0);
 } elsif ($action eq 'status') {
 } elsif ($action eq 'status') {
     # Prefix everything with "dpkg-buildflags: status: " to allow easy
     # Prefix everything with "dpkg-buildflags: status: " to allow easy
     # extraction from a build log. Thus we use report with a non-translated
     # 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' : '';
 	my $maintainer = $build_flags->is_maintainer_modified($flag) ? '+maintainer' : '';
 	print report('status', "$flag [$origin$maintainer]: $value");
 	print report('status', "$flag [$origin$maintainer]: $value");
     }
     }
-    exit(0);
 }
 }
-
-exit(1);