mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 22:16:16 +02:00
feat: read installable paths from stdin
Resolves #7437 for new `nix` commands only by adding a `--stdin` flag. If paths are also passed on the cli they will be combined with the ones from standard input.
This commit is contained in:
parent
db14e1d4ae
commit
269caa5317
2 changed files with 18 additions and 1 deletions
|
@ -128,6 +128,8 @@ struct InstallablesCommand : virtual Args, SourceExprCommand
|
||||||
|
|
||||||
virtual bool useDefaultInstallables() { return true; }
|
virtual bool useDefaultInstallables() { return true; }
|
||||||
|
|
||||||
|
bool readFromStdIn;
|
||||||
|
|
||||||
std::vector<std::string> getFlakesForCompletion() override;
|
std::vector<std::string> getFlakesForCompletion() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -691,6 +691,13 @@ StorePathSet Installable::toDerivations(
|
||||||
|
|
||||||
InstallablesCommand::InstallablesCommand()
|
InstallablesCommand::InstallablesCommand()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
addFlag({
|
||||||
|
.longName = "stdin",
|
||||||
|
.description = "Read installables from the standard input.",
|
||||||
|
.handler = {&readFromStdIn, true}
|
||||||
|
});
|
||||||
|
|
||||||
expectArgs({
|
expectArgs({
|
||||||
.label = "installables",
|
.label = "installables",
|
||||||
.handler = {&_installables},
|
.handler = {&_installables},
|
||||||
|
@ -707,10 +714,18 @@ void InstallablesCommand::prepare()
|
||||||
|
|
||||||
Installables InstallablesCommand::load()
|
Installables InstallablesCommand::load()
|
||||||
{
|
{
|
||||||
if (_installables.empty() && useDefaultInstallables())
|
if (_installables.empty() && useDefaultInstallables() && !readFromStdIn)
|
||||||
// FIXME: commands like "nix profile install" should not have a
|
// FIXME: commands like "nix profile install" should not have a
|
||||||
// default, probably.
|
// default, probably.
|
||||||
_installables.push_back(".");
|
_installables.push_back(".");
|
||||||
|
|
||||||
|
if (readFromStdIn && !isatty(STDIN_FILENO)) {
|
||||||
|
std::string word;
|
||||||
|
while (std::cin >> word) {
|
||||||
|
_installables.emplace_back(std::move(word));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return parseInstallables(getStore(), _installables);
|
return parseInstallables(getStore(), _installables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue