mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2025-02-08 19:27:18 +02:00
patch: nix-dram
This commit is contained in:
parent
244636e599
commit
47f5d658a5
4 changed files with 59 additions and 16 deletions
|
@ -20,6 +20,10 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
const static std::regex attrPathRegex(
|
||||||
|
R"((?:[a-zA-Z0-9_"-][a-zA-Z0-9_".-]*))",
|
||||||
|
std::regex::ECMAScript);
|
||||||
|
|
||||||
void completeFlakeInputPath(
|
void completeFlakeInputPath(
|
||||||
ref<EvalState> evalState,
|
ref<EvalState> evalState,
|
||||||
const FlakeRef & flakeRef,
|
const FlakeRef & flakeRef,
|
||||||
|
@ -234,12 +238,21 @@ void completeFlakeRefWithFragment(
|
||||||
/* Look for flake output attributes that match the
|
/* Look for flake output attributes that match the
|
||||||
prefix. */
|
prefix. */
|
||||||
try {
|
try {
|
||||||
|
bool isAttrPath = std::regex_match(prefix.begin(), prefix.end(), attrPathRegex);
|
||||||
auto hash = prefix.find('#');
|
auto hash = prefix.find('#');
|
||||||
if (hash == std::string::npos) {
|
if (!isAttrPath && hash == std::string::npos) {
|
||||||
completeFlakeRef(evalState->store, prefix);
|
completeFlakeRef(evalState->store, prefix);
|
||||||
} else {
|
} else {
|
||||||
auto fragment = prefix.substr(hash + 1);
|
auto fragment =
|
||||||
auto flakeRefS = std::string(prefix.substr(0, hash));
|
isAttrPath
|
||||||
|
? prefix
|
||||||
|
: prefix.substr(hash + 1);
|
||||||
|
|
||||||
|
auto flakeRefS =
|
||||||
|
isAttrPath
|
||||||
|
? std::string("flake:default")
|
||||||
|
: std::string(prefix.substr(0, hash));
|
||||||
|
|
||||||
// FIXME: do tilde expansion.
|
// FIXME: do tilde expansion.
|
||||||
auto flakeRef = parseFlakeRef(flakeRefS, absPath("."));
|
auto flakeRef = parseFlakeRef(flakeRefS, absPath("."));
|
||||||
|
|
||||||
|
@ -274,7 +287,10 @@ void completeFlakeRefWithFragment(
|
||||||
auto attrPath2 = attr->getAttrPath(attr2);
|
auto attrPath2 = attr->getAttrPath(attr2);
|
||||||
/* Strip the attrpath prefix. */
|
/* Strip the attrpath prefix. */
|
||||||
attrPath2.erase(attrPath2.begin(), attrPath2.begin() + attrPathPrefix.size());
|
attrPath2.erase(attrPath2.begin(), attrPath2.begin() + attrPathPrefix.size());
|
||||||
completions->add(flakeRefS + "#" + concatStringsSep(".", attrPath2));
|
if (isAttrPath)
|
||||||
|
completions->add(concatStringsSep(".", attrPath2));
|
||||||
|
else
|
||||||
|
completions->add(flakeRefS + "#" + concatStringsSep(".", attrPath2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,7 +765,13 @@ std::vector<std::shared_ptr<Installable>> SourceExprCommand::parseInstallables(
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
auto [flakeRef, fragment] = parseFlakeRefWithFragment(s, absPath("."));
|
bool isAttrPath = std::regex_match(s, attrPathRegex);
|
||||||
|
|
||||||
|
auto [flakeRef, fragment] =
|
||||||
|
isAttrPath
|
||||||
|
? std::make_pair(parseFlakeRef("flake:default", absPath(".")), s)
|
||||||
|
: parseFlakeRefWithFragment(s, absPath("."));
|
||||||
|
|
||||||
result.push_back(std::make_shared<InstallableFlake>(
|
result.push_back(std::make_shared<InstallableFlake>(
|
||||||
this,
|
this,
|
||||||
getEvalState(),
|
getEvalState(),
|
||||||
|
|
|
@ -21,13 +21,32 @@ std::string wrap(std::string prefix, std::string s)
|
||||||
return prefix + s + ANSI_NORMAL;
|
return prefix + s + ANSI_NORMAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CmdSearch : InstallableCommand, MixJSON
|
struct CmdSearch : SourceExprCommand, MixJSON
|
||||||
{
|
{
|
||||||
|
std::string _installable{"flake:default"};
|
||||||
std::vector<std::string> res;
|
std::vector<std::string> res;
|
||||||
|
|
||||||
CmdSearch()
|
CmdSearch()
|
||||||
{
|
{
|
||||||
expectArgs("regex", &res);
|
bool hasInstallable = false;
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "installable",
|
||||||
|
.shortName = 'i',
|
||||||
|
.description = "Search within this installable",
|
||||||
|
.labels = {"installable"},
|
||||||
|
.handler = {[this, &hasInstallable](std::string ss) {
|
||||||
|
hasInstallable = true;
|
||||||
|
_installable = ss;
|
||||||
|
}},
|
||||||
|
.completer = completePath
|
||||||
|
});
|
||||||
|
|
||||||
|
if (hasInstallable && (file || expr)) {
|
||||||
|
throw UsageError("'--installable' cannot be used together with '--file' or '--expr'");
|
||||||
|
}
|
||||||
|
|
||||||
|
expectArgs("args", &res);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string description() override
|
std::string description() override
|
||||||
|
@ -55,6 +74,8 @@ struct CmdSearch : InstallableCommand, MixJSON
|
||||||
settings.readOnlyMode = true;
|
settings.readOnlyMode = true;
|
||||||
evalSettings.enableImportFromDerivation.setDefault(false);
|
evalSettings.enableImportFromDerivation.setDefault(false);
|
||||||
|
|
||||||
|
auto installable = parseInstallable(store, (file || expr) ? "" : _installable);
|
||||||
|
|
||||||
// Empty search string should match all packages
|
// Empty search string should match all packages
|
||||||
// Use "^" here instead of ".*" due to differences in resulting highlighting
|
// Use "^" here instead of ".*" due to differences in resulting highlighting
|
||||||
// (see #1893 -- libc++ claims empty search string is not in POSIX grammar)
|
// (see #1893 -- libc++ claims empty search string is not in POSIX grammar)
|
||||||
|
|
|
@ -129,7 +129,7 @@ nix build -o $TEST_ROOT/result flake1#foo
|
||||||
[[ -e $TEST_ROOT/result/hello ]]
|
[[ -e $TEST_ROOT/result/hello ]]
|
||||||
|
|
||||||
# Test defaultPackage.
|
# Test defaultPackage.
|
||||||
nix build -o $TEST_ROOT/result flake1
|
nix build -o $TEST_ROOT/result flake1#
|
||||||
[[ -e $TEST_ROOT/result/hello ]]
|
[[ -e $TEST_ROOT/result/hello ]]
|
||||||
|
|
||||||
nix build -o $TEST_ROOT/result $flake1Dir
|
nix build -o $TEST_ROOT/result $flake1Dir
|
||||||
|
|
|
@ -3,26 +3,26 @@ source common.sh
|
||||||
clearStore
|
clearStore
|
||||||
clearCache
|
clearCache
|
||||||
|
|
||||||
(( $(nix search -f search.nix '' hello | wc -l) > 0 ))
|
(( $(nix search -f search.nix hello | wc -l) > 0 ))
|
||||||
|
|
||||||
# Check descriptions are searched
|
# Check descriptions are searched
|
||||||
(( $(nix search -f search.nix '' broken | wc -l) > 0 ))
|
(( $(nix search -f search.nix broken | wc -l) > 0 ))
|
||||||
|
|
||||||
# Check search that matches nothing
|
# Check search that matches nothing
|
||||||
(( $(nix search -f search.nix '' nosuchpackageexists | wc -l) == 0 ))
|
(( $(nix search -f search.nix nosuchpackageexists | wc -l) == 0 ))
|
||||||
|
|
||||||
# Search for multiple arguments
|
# Search for multiple arguments
|
||||||
(( $(nix search -f search.nix '' hello empty | wc -l) == 2 ))
|
(( $(nix search -f search.nix hello empty | wc -l) == 2 ))
|
||||||
|
|
||||||
# Multiple arguments will not exist
|
# Multiple arguments will not exist
|
||||||
(( $(nix search -f search.nix '' hello broken | wc -l) == 0 ))
|
(( $(nix search -f search.nix hello broken | wc -l) == 0 ))
|
||||||
|
|
||||||
## Search expressions
|
## Search expressions
|
||||||
|
|
||||||
# Check that empty search string matches all
|
# Check that empty search string matches all
|
||||||
nix search -f search.nix '' |grep -q foo
|
nix search -f search.nix |grep -q foo
|
||||||
nix search -f search.nix '' |grep -q bar
|
nix search -f search.nix |grep -q bar
|
||||||
nix search -f search.nix '' |grep -q hello
|
nix search -f search.nix |grep -q hello
|
||||||
|
|
||||||
## Tests for multiple regex/match highlighting
|
## Tests for multiple regex/match highlighting
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue