forked from lix-project/lix
Fix nix shebang interaction with #8131 overhaul completions
This commit is contained in:
parent
e91fd837ee
commit
ffd414eb75
4 changed files with 25 additions and 29 deletions
|
@ -294,7 +294,9 @@ void completeFlakeRefWithFragment(
|
||||||
prefixRoot = ".";
|
prefixRoot = ".";
|
||||||
}
|
}
|
||||||
auto flakeRefS = std::string(prefix.substr(0, hash));
|
auto flakeRefS = std::string(prefix.substr(0, hash));
|
||||||
auto flakeRef = parseFlakeRef(expandTilde(flakeRefS), absPath(getCommandBaseDir()));
|
|
||||||
|
// TODO: ideally this would use the command base directory instead of assuming ".".
|
||||||
|
auto flakeRef = parseFlakeRef(expandTilde(flakeRefS), absPath("."));
|
||||||
|
|
||||||
auto evalCache = openEvalCache(*evalState,
|
auto evalCache = openEvalCache(*evalState,
|
||||||
std::make_shared<flake::LockedFlake>(lockFlake(*evalState, flakeRef, lockFlags)));
|
std::make_shared<flake::LockedFlake>(lockFlake(*evalState, flakeRef, lockFlags)));
|
||||||
|
|
|
@ -80,12 +80,6 @@ std::optional<std::string> RootArgs::needsCompletion(std::string_view s)
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void RootArgs::parseCmdline(const Strings & _cmdline)
|
|
||||||
{
|
|
||||||
// Default via 5.1.2.2.1 in C standard
|
|
||||||
Args::parseCmdline(_cmdline, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Basically this is `typedef std::optional<Parser> Parser(std::string_view s, Strings & r);`
|
* Basically this is `typedef std::optional<Parser> Parser(std::string_view s, Strings & r);`
|
||||||
*
|
*
|
||||||
|
@ -227,7 +221,7 @@ static Strings parseShebangContent(std::string_view s) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Args::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
||||||
{
|
{
|
||||||
Strings pendingArgs;
|
Strings pendingArgs;
|
||||||
bool dashDash = false;
|
bool dashDash = false;
|
||||||
|
@ -339,9 +333,12 @@ void Args::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
||||||
|
|
||||||
Path Args::getCommandBaseDir() const
|
Path Args::getCommandBaseDir() const
|
||||||
{
|
{
|
||||||
if (parent)
|
assert(parent);
|
||||||
return parent->getCommandBaseDir();
|
return parent->getCommandBaseDir();
|
||||||
else
|
}
|
||||||
|
|
||||||
|
Path RootArgs::getCommandBaseDir() const
|
||||||
|
{
|
||||||
return commandBaseDir;
|
return commandBaseDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,24 +24,9 @@ class AddCompletions;
|
||||||
|
|
||||||
class Args
|
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:
|
public:
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse the command line with argv0, throwing a UsageError if something
|
|
||||||
goes wrong.
|
|
||||||
*/
|
|
||||||
void parseCmdline(const Strings & _cmdline, bool allowShebang);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a short one-line description of the command.
|
* Return a short one-line description of the command.
|
||||||
*/
|
*/
|
||||||
|
@ -62,7 +47,7 @@ public:
|
||||||
*
|
*
|
||||||
* This only returns the correct value after parseCmdline() has run.
|
* This only returns the correct value after parseCmdline() has run.
|
||||||
*/
|
*/
|
||||||
Path getCommandBaseDir() const;
|
virtual Path getCommandBaseDir() const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,26 @@ struct Completions final : AddCompletions
|
||||||
*/
|
*/
|
||||||
class RootArgs : virtual public Args
|
class RootArgs : virtual public 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:
|
public:
|
||||||
/** Parse the command line, throwing a UsageError if something goes
|
/** Parse the command line, throwing a UsageError if something goes
|
||||||
* wrong.
|
* wrong.
|
||||||
*/
|
*/
|
||||||
void parseCmdline(const Strings & cmdline);
|
void parseCmdline(const Strings & cmdline, bool allowShebang = false);
|
||||||
|
|
||||||
std::shared_ptr<Completions> completions;
|
std::shared_ptr<Completions> completions;
|
||||||
|
|
||||||
|
Path getCommandBaseDir() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
friend class Args;
|
friend class Args;
|
||||||
|
|
Loading…
Reference in a new issue