about summary refs log tree commit diff
path: root/scripts/nix-prefetch-url.in
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-23T16·04+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-10-23T16·04+0200
commita28b4445a4eb8108dfc028083d3939d5f3a42685 (patch)
treebbf989d956ab6b3ea2830d75c79d5adc69c7664f /scripts/nix-prefetch-url.in
parent2980d1fba97069805c3649c5d99d0356bce6c303 (diff)
nix-prefetch-url: Improve option handling
Diffstat (limited to 'scripts/nix-prefetch-url.in')
-rwxr-xr-xscripts/nix-prefetch-url.in23
1 files changed, 20 insertions, 3 deletions
diff --git a/scripts/nix-prefetch-url.in b/scripts/nix-prefetch-url.in
index 64102e8ae84a..bcd9197bcff1 100755
--- a/scripts/nix-prefetch-url.in
+++ b/scripts/nix-prefetch-url.in
@@ -8,11 +8,28 @@ use Nix::Store;
 use Nix::Config;
 use Nix::Utils;
 
-my $url = shift;
-my $expHash = shift;
-my $hashType = $ENV{'NIX_HASH_ALGO'} || "sha256";
+my $hashType = $ENV{'NIX_HASH_ALGO'} || "sha256"; # obsolete
 my $cacheDir = $ENV{'NIX_DOWNLOAD_CACHE'};
 
+my @args;
+my $arg;
+while ($arg = shift) {
+    if ($arg eq "--help") {
+        exec "man nix-prefetch-url" or die;
+    } elsif ($arg eq "--type") {
+        $hashType = shift;
+        die "$0: `$arg' requires an argument\n" unless defined $hashType;
+    } elsif (substr($arg, 0, 1) eq "-") {
+        die "$0: unknown flag `$arg'\n";
+    } else {
+        push @args, $arg;
+    }
+}
+
+my $url = $args[0];
+my $expHash = $args[1];
+
+
 if (!defined $url || $url eq "") {
     print STDERR <<EOF
 Usage: nix-prefetch-url URL [EXPECTED-HASH]