mirror of
https://github.com/NixOS/nix
synced 2025-07-01 04:18:00 +02:00
Fix handling of experimental features mid-parse
If we conditionally "declare" the argument, as we did before, based upon weather the feature is enabled, commands like nix --experimental-features=foo ... --thing-gated-on-foo won't work, because the experimental feature isn't enabled until *after* we start parsing. Instead, allow arguments to also be associated with experimental features (just as we did for builtins and settings), and then the command line parser will filter out the experimental ones. Since the effects of arguments (handler functions) are performed right away, we get the required behavior: earlier arguments can enable later arguments enabled! There is just one catch: we want to keep non-positional flags...non-positional. So if nix --experimental-features=foo ... --thing-gated-on-foo works, then nix --thing-gated-on-foo --experimental-features=foo ... should also work. This is not my favorite long-term solution, but for now this is implemented by delaying the requirement of needed experimental features until *after* all the arguments have been parsed.
This commit is contained in:
parent
aa663b7e89
commit
4607ac7aed
5 changed files with 53 additions and 16 deletions
|
@ -117,6 +117,8 @@ protected:
|
|||
Handler handler;
|
||||
std::function<void(size_t, std::string_view)> completer;
|
||||
|
||||
std::optional<ExperimentalFeature> experimentalFeature;
|
||||
|
||||
static Flag mkHashTypeFlag(std::string && longName, HashType * ht);
|
||||
static Flag mkHashTypeOptFlag(std::string && longName, std::optional<HashType> * oht);
|
||||
};
|
||||
|
@ -188,6 +190,16 @@ public:
|
|||
friend class MultiCommand;
|
||||
|
||||
MultiCommand * parent = nullptr;
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Experimental features needed when parsing args. These are checked
|
||||
* after flag parsing is completed in order to support enabling
|
||||
* experimental features coming after the flag that needs the
|
||||
* experimental feature.
|
||||
*/
|
||||
std::set<ExperimentalFeature> flagExperimentalFeatures;
|
||||
};
|
||||
|
||||
/* A command is an argument parser that can be executed by calling its
|
||||
|
@ -253,8 +265,6 @@ enum CompletionType {
|
|||
};
|
||||
extern CompletionType completionType;
|
||||
|
||||
std::optional<std::string> needsCompletion(std::string_view s);
|
||||
|
||||
void completePath(size_t, std::string_view prefix);
|
||||
|
||||
void completeDir(size_t, std::string_view prefix);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue