mirror of
https://github.com/NixOS/nix
synced 2025-07-06 17:31:47 +02:00
nix: Add command baseDir to parse --expr relative to shebang script
This commit is contained in:
parent
20ff61ab25
commit
198bc22e3b
5 changed files with 51 additions and 1 deletions
|
@ -276,6 +276,7 @@ void Args::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
|||
cmdline.push_back(word);
|
||||
}
|
||||
cmdline.push_back(script);
|
||||
commandBaseDir = dirOf(script);
|
||||
for (auto pos = savedArgs.begin(); pos != savedArgs.end();pos++)
|
||||
cmdline.push_back(*pos);
|
||||
}
|
||||
|
@ -336,6 +337,14 @@ void Args::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
|||
d.completer(*completions, d.n, d.prefix);
|
||||
}
|
||||
|
||||
Path Args::getCommandBaseDir() const
|
||||
{
|
||||
if (parent)
|
||||
return parent->getCommandBaseDir();
|
||||
else
|
||||
return commandBaseDir;
|
||||
}
|
||||
|
||||
bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
|
||||
{
|
||||
assert(pos != end);
|
||||
|
|
|
@ -24,6 +24,16 @@ class AddCompletions;
|
|||
|
||||
class Args
|
||||
{
|
||||
/**
|
||||
* @brief The command's "working directory", but only set when top level.
|
||||
*
|
||||
* Use getCommandBaseDir() to get the directory regardless of whether this
|
||||
* is a top-level command or subcommand.
|
||||
*
|
||||
* @see getCommandBaseDir()
|
||||
*/
|
||||
Path commandBaseDir = ".";
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
|
@ -44,6 +54,16 @@ public:
|
|||
*/
|
||||
virtual std::string doc() { return ""; }
|
||||
|
||||
/**
|
||||
* @brief Get the base directory for the command.
|
||||
*
|
||||
* @return Generally the working directory, but in case of a shebang
|
||||
* interpreter, returns the directory of the script.
|
||||
*
|
||||
* This only returns the correct value after parseCmdline() has run.
|
||||
*/
|
||||
Path getCommandBaseDir() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue