nix-prefetch-url: $PRINT_PATH -> --print-path

This commit is contained in:
Eelco Dolstra 2015-10-01 16:53:07 +02:00
parent bec3c31608
commit a3c4eb0964
2 changed files with 23 additions and 12 deletions

View file

@ -54,8 +54,8 @@ error if signaled if the actual hash of the file does not match the
specified hash.</para> specified hash.</para>
<para>This command prints the hash on standard output. Additionally, <para>This command prints the hash on standard output. Additionally,
if the environment variable <envar>PRINT_PATH</envar> is set, the path if the option <option>--print-path</option> is used, the path of the
of the downloaded file in the Nix store is also printed.</para> downloaded file in the Nix store is also printed.</para>
</refsection> </refsection>
@ -73,6 +73,13 @@ of the downloaded file in the Nix store is also printed.</para>
</varlistentry> </varlistentry>
<varlistentry><term><option>--print-path</option></term>
<listitem><para>Print the store path of the downloaded file on
standard output.</para></listitem>
</varlistentry>
</variablelist> </variablelist>
</refsection> </refsection>
@ -81,12 +88,12 @@ of the downloaded file in the Nix store is also printed.</para>
<refsection><title>Examples</title> <refsection><title>Examples</title>
<screen> <screen>
$ nix-prefetch-url ftp://ftp.nluug.nl/pub/gnu/make/make-3.80.tar.bz2 $ nix-prefetch-url ftp://ftp.gnu.org/pub/gnu/hello/hello-2.10.tar.gz
0bbd1df101bc0294d440471e50feca71 0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
$ PRINT_PATH=1 nix-prefetch-url ftp://ftp.nluug.nl/pub/gnu/make/make-3.80.tar.bz2 $ nix-prefetch-url --print-path mirror://gnu/hello/hello-2.10.tar.gz
0bbd1df101bc0294d440471e50feca71 0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89ndq1i
/nix/store/wvyz8ifdn7wyz1p3pqyn0ra45ka2l492-make-3.80.tar.bz2</screen> /nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz</screen>
</refsection> </refsection>

View file

@ -48,6 +48,7 @@ int main(int argc, char * * argv)
HashType ht = htSHA256; HashType ht = htSHA256;
std::vector<string> args; std::vector<string> args;
Strings searchPath; Strings searchPath;
bool printPath = getEnv("PRINT_PATH") != "";
parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) { parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) {
if (*arg == "--help") if (*arg == "--help")
@ -60,6 +61,8 @@ int main(int argc, char * * argv)
if (ht == htUnknown) if (ht == htUnknown)
throw UsageError(format("unknown hash type %1%") % s); throw UsageError(format("unknown hash type %1%") % s);
} }
else if (*arg == "--print-path")
printPath = true;
else if (parseSearchPathArg(arg, end, searchPath)) else if (parseSearchPathArg(arg, end, searchPath))
; ;
else if (*arg != "" && arg->at(0) == '-') else if (*arg != "" && arg->at(0) == '-')
@ -123,10 +126,11 @@ int main(int argc, char * * argv)
storePath = store->addToStore(name, tmpFile, false, ht); storePath = store->addToStore(name, tmpFile, false, ht);
} }
if (!printPath)
printMsg(lvlInfo, format("path is %1%") % storePath); printMsg(lvlInfo, format("path is %1%") % storePath);
std::cout << printHash16or32(hash) << std::endl; std::cout << printHash16or32(hash) << std::endl;
if (getEnv("PRINT_PATH") != "") if (printPath)
std::cout << storePath << std::endl; std::cout << storePath << std::endl;
}); });
} }