aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-07-24 20:42:24 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-12-03 18:09:02 +0100
commitef583303f0720d8bc9d6351cd769f92d5dd678f3 (patch)
tree8d15ff9adc90fb7d6a2499a33936e6ed0049f219
parent79c1967ded92574129c6a20116ef205a9c747bac (diff)
Move NAR-related commands to 'nix nar'
-rw-r--r--src/nix/cat.cc6
-rw-r--r--src/nix/ls.cc8
-rw-r--r--src/nix/nar.cc31
-rw-r--r--tests/binary-cache.sh6
-rw-r--r--tests/linux-sandbox.sh4
-rw-r--r--tests/nar-access.sh26
6 files changed, 54 insertions, 27 deletions
diff --git a/src/nix/cat.cc b/src/nix/cat.cc
index eef172cfc..4fa1c9491 100644
--- a/src/nix/cat.cc
+++ b/src/nix/cat.cc
@@ -64,13 +64,11 @@ struct CmdCatNar : StoreCommand, MixCat
return "print the contents of a file inside a NAR file on stdout";
}
- Category category() override { return catUtility; }
-
void run(ref<Store> store) override
{
cat(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
}
};
-static auto rCmdCatStore = registerCommand<CmdCatStore>("cat-store");
-static auto rCmdCatNar = registerCommand<CmdCatNar>("cat-nar");
+static auto rCmdCatStore = registerCommand2<CmdCatStore>({"store", "cat"});
+static auto rCmdCatNar = registerCommand2<CmdCatNar>({"nar", "cat"});
diff --git a/src/nix/ls.cc b/src/nix/ls.cc
index f39fdb2fd..d5fec4d84 100644
--- a/src/nix/ls.cc
+++ b/src/nix/ls.cc
@@ -134,7 +134,7 @@ struct CmdLsNar : Command, MixLs
return {
Example{
"To list a specific file in a NAR:",
- "nix ls-nar -l hello.nar /bin/hello"
+ "nix nar ls -l hello.nar /bin/hello"
},
};
}
@@ -144,13 +144,11 @@ struct CmdLsNar : Command, MixLs
return "show information about a path inside a NAR file";
}
- Category category() override { return catUtility; }
-
void run() override
{
list(makeNarAccessor(make_ref<std::string>(readFile(narPath))));
}
};
-static auto rCmdLsStore = registerCommand<CmdLsStore>("ls-store");
-static auto rCmdLsNar = registerCommand<CmdLsNar>("ls-nar");
+static auto rCmdLsStore = registerCommand2<CmdLsStore>({"store", "ls"});
+static auto rCmdLsNar = registerCommand2<CmdLsNar>({"nar", "ls"});
diff --git a/src/nix/nar.cc b/src/nix/nar.cc
new file mode 100644
index 000000000..e239ce96a
--- /dev/null
+++ b/src/nix/nar.cc
@@ -0,0 +1,31 @@
+#include "command.hh"
+
+using namespace nix;
+
+struct CmdNar : NixMultiCommand
+{
+ CmdNar() : MultiCommand(RegisterCommand::getCommandsFor({"nar"}))
+ { }
+
+ std::string description() override
+ {
+ return "query the contents of NAR files";
+ }
+
+ Category category() override { return catUtility; }
+
+ void run() override
+ {
+ if (!command)
+ throw UsageError("'nix nar' requires a sub-command.");
+ command->second->prepare();
+ command->second->run();
+ }
+
+ void printHelp(const string & programName, std::ostream & out) override
+ {
+ MultiCommand::printHelp(programName, out);
+ }
+};
+
+static auto rCmdNar = registerCommand<CmdNar>("nar");
diff --git a/tests/binary-cache.sh b/tests/binary-cache.sh
index e3b3982fe..8cb17caf8 100644
--- a/tests/binary-cache.sh
+++ b/tests/binary-cache.sh
@@ -196,13 +196,13 @@ narCache=$TEST_ROOT/nar-cache
rm -rf $narCache
mkdir $narCache
-[[ $(nix cat-store --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
+[[ $(nix store cat --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
rm -rfv "$cacheDir/nar"
-[[ $(nix cat-store --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
+[[ $(nix store cat --store "file://$cacheDir?local-nar-cache=$narCache" $outPath/foobar) = FOOBAR ]]
-(! nix cat-store --store file://$cacheDir $outPath/foobar)
+(! nix store cat --store file://$cacheDir $outPath/foobar)
# Test NAR listing generation.
diff --git a/tests/linux-sandbox.sh b/tests/linux-sandbox.sh
index 16abd974c..70a90a907 100644
--- a/tests/linux-sandbox.sh
+++ b/tests/linux-sandbox.sh
@@ -22,9 +22,9 @@ outPath=$(nix-build dependencies.nix --no-out-link --sandbox-paths /nix/store)
nix path-info -r $outPath | grep input-2
-nix ls-store -R -l $outPath | grep foobar
+nix store ls -R -l $outPath | grep foobar
-nix cat-store $outPath/foobar | grep FOOBAR
+nix store cat $outPath/foobar | grep FOOBAR
# Test --check without hash rewriting.
nix-build dependencies.nix --no-out-link --check --sandbox-paths /nix/store
diff --git a/tests/nar-access.sh b/tests/nar-access.sh
index 88b997ca6..dcc2e8a36 100644
--- a/tests/nar-access.sh
+++ b/tests/nar-access.sh
@@ -9,45 +9,45 @@ cd "$TEST_ROOT"
narFile="$TEST_ROOT/path.nar"
nix-store --dump $storePath > $narFile
-# Check that find and ls-nar match.
+# Check that find and nar ls match.
( cd $storePath; find . | sort ) > files.find
-nix ls-nar -R -d $narFile "" | sort > files.ls-nar
+nix nar ls -R -d $narFile "" | sort > files.ls-nar
diff -u files.find files.ls-nar
# Check that file contents of data match.
-nix cat-nar $narFile /foo/data > data.cat-nar
+nix nar cat $narFile /foo/data > data.cat-nar
diff -u data.cat-nar $storePath/foo/data
# Check that file contents of baz match.
-nix cat-nar $narFile /foo/baz > baz.cat-nar
+nix nar cat $narFile /foo/baz > baz.cat-nar
diff -u baz.cat-nar $storePath/foo/baz
-nix cat-store $storePath/foo/baz > baz.cat-nar
+nix store cat $storePath/foo/baz > baz.cat-nar
diff -u baz.cat-nar $storePath/foo/baz
# Test --json.
diff -u \
- <(nix ls-nar --json $narFile / | jq -S) \
+ <(nix nar ls --json $narFile / | jq -S) \
<(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S)
diff -u \
- <(nix ls-nar --json -R $narFile /foo | jq -S) \
+ <(nix nar ls --json -R $narFile /foo | jq -S) \
<(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0,"narOffset":368},"baz":{"type":"regular","size":0,"narOffset":552},"data":{"type":"regular","size":58,"narOffset":736}}}' | jq -S)
diff -u \
- <(nix ls-nar --json -R $narFile /foo/bar | jq -S) \
+ <(nix nar ls --json -R $narFile /foo/bar | jq -S) \
<(echo '{"type":"regular","size":0,"narOffset":368}' | jq -S)
diff -u \
- <(nix ls-store --json $storePath | jq -S) \
+ <(nix store ls --json $storePath | jq -S) \
<(echo '{"type":"directory","entries":{"foo":{},"foo-x":{},"qux":{},"zyx":{}}}' | jq -S)
diff -u \
- <(nix ls-store --json -R $storePath/foo | jq -S) \
+ <(nix store ls --json -R $storePath/foo | jq -S) \
<(echo '{"type":"directory","entries":{"bar":{"type":"regular","size":0},"baz":{"type":"regular","size":0},"data":{"type":"regular","size":58}}}' | jq -S)
diff -u \
- <(nix ls-store --json -R $storePath/foo/bar| jq -S) \
+ <(nix store ls --json -R $storePath/foo/bar| jq -S) \
<(echo '{"type":"regular","size":0}' | jq -S)
# Test missing files.
-nix ls-store --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
-nix ls-store $storePath/xyzzy 2>&1 | grep 'does not exist'
+nix store ls --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
+nix store ls $storePath/xyzzy 2>&1 | grep 'does not exist'
# Test failure to dump.
if nix-store --dump $storePath >/dev/full ; then