diff options
author | Timothy DeHerrera <tim@nrdxp.dev> | 2023-01-12 12:35:22 -0700 |
---|---|---|
committer | Timothy DeHerrera <tim@nrdxp.dev> | 2023-02-28 12:29:15 -0700 |
commit | 269caa531729524915761f8a71e47e59e6a8598d (patch) | |
tree | 07e8569776eb89ff9d5f45d104c1e531755fb70d /src/libcmd/installables.cc | |
parent | db14e1d4aeb206e302f9cd9f02a10e9be0499e2c (diff) |
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.
Diffstat (limited to 'src/libcmd/installables.cc')
-rw-r--r-- | src/libcmd/installables.cc | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index 00c6f9516..a67841bb6 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -691,6 +691,13 @@ StorePathSet Installable::toDerivations( InstallablesCommand::InstallablesCommand() { + + addFlag({ + .longName = "stdin", + .description = "Read installables from the standard input.", + .handler = {&readFromStdIn, true} + }); + expectArgs({ .label = "installables", .handler = {&_installables}, @@ -707,10 +714,18 @@ void InstallablesCommand::prepare() Installables InstallablesCommand::load() { - if (_installables.empty() && useDefaultInstallables()) + if (_installables.empty() && useDefaultInstallables() && !readFromStdIn) // FIXME: commands like "nix profile install" should not have a // default, probably. _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); } |