mirror of
https://github.com/NixOS/nix
synced 2025-07-07 01:51:47 +02:00
Stuctured command stability
Prior to this, there was an ad-hoc whitelist in `main.cc`. Now, every command states its stability. In a future PR, we will adjust the manual to take advantage of this new information in the JSON. (It will be easier to do that once we have some experimental feature docs to link too; see #5930 and #7798.)
This commit is contained in:
parent
f3a6de6ba9
commit
4a0b893d5e
7 changed files with 51 additions and 9 deletions
|
@ -236,8 +236,6 @@ nlohmann::json Args::toJSON()
|
|||
auto flags = nlohmann::json::object();
|
||||
|
||||
for (auto & [name, flag] : longFlags) {
|
||||
/* Skip experimental flags when listing flags. */
|
||||
if (!experimentalFeatureSettings.isEnabled(flag->experimentalFeature)) continue;
|
||||
auto j = nlohmann::json::object();
|
||||
if (flag->aliases.count(name)) continue;
|
||||
if (flag->shortName)
|
||||
|
@ -249,6 +247,11 @@ nlohmann::json Args::toJSON()
|
|||
j["arity"] = flag->handler.arity;
|
||||
if (!flag->labels.empty())
|
||||
j["labels"] = flag->labels;
|
||||
// TODO With C++23 use `std::optional::tranform`
|
||||
if (auto & xp = flag->experimentalFeature)
|
||||
j["experimental-feature"] = showExperimentalFeature(*xp);
|
||||
else
|
||||
j["experimental-feature"] = nullptr;
|
||||
flags[name] = std::move(j);
|
||||
}
|
||||
|
||||
|
@ -345,6 +348,11 @@ Strings argvToStrings(int argc, char * * argv)
|
|||
return args;
|
||||
}
|
||||
|
||||
std::optional<ExperimentalFeature> Command::experimentalFeature ()
|
||||
{
|
||||
return { Xp::NixCommand };
|
||||
}
|
||||
|
||||
MultiCommand::MultiCommand(const Commands & commands_)
|
||||
: commands(commands_)
|
||||
{
|
||||
|
@ -408,6 +416,11 @@ nlohmann::json MultiCommand::toJSON()
|
|||
cat["id"] = command->category();
|
||||
cat["description"] = trim(categories[command->category()]);
|
||||
j["category"] = std::move(cat);
|
||||
// TODO With C++23 use `std::optional::tranform`
|
||||
if (auto xp = command->experimentalFeature())
|
||||
cat["experimental-feature"] = showExperimentalFeature(*xp);
|
||||
else
|
||||
cat["experimental-feature"] = nullptr;
|
||||
cmds[name] = std::move(j);
|
||||
}
|
||||
|
||||
|
|
|
@ -236,6 +236,8 @@ struct Command : virtual public Args
|
|||
|
||||
static constexpr Category catDefault = 0;
|
||||
|
||||
virtual std::optional<ExperimentalFeature> experimentalFeature ();
|
||||
|
||||
virtual Category category() { return catDefault; }
|
||||
};
|
||||
|
||||
|
|
|
@ -39,6 +39,14 @@ struct CmdDoctor : StoreCommand
|
|||
{
|
||||
bool success = true;
|
||||
|
||||
/**
|
||||
* This command is stable before the others
|
||||
*/
|
||||
std::optional<ExperimentalFeature> experimentalFeature() override
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "check your system for potential problems and print a PASS or FAIL for each check";
|
||||
|
|
|
@ -423,10 +423,8 @@ void mainWrapped(int argc, char * * argv)
|
|||
if (!args.command)
|
||||
throw UsageError("no subcommand specified");
|
||||
|
||||
if (args.command->first != "repl"
|
||||
&& args.command->first != "doctor"
|
||||
&& args.command->first != "upgrade-nix")
|
||||
experimentalFeatureSettings.require(Xp::NixCommand);
|
||||
experimentalFeatureSettings.require(
|
||||
args.command->second->experimentalFeature());
|
||||
|
||||
if (args.useNet && !haveInternet()) {
|
||||
warn("you don't have Internet access; disabling some network-dependent features");
|
||||
|
|
|
@ -12,6 +12,14 @@ struct CmdRepl : RawInstallablesCommand
|
|||
evalSettings.pureEval = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* This command is stable before the others
|
||||
*/
|
||||
std::optional<ExperimentalFeature> experimentalFeature() override
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::vector<std::string> files;
|
||||
|
||||
Strings getDefaultFlakeAttrPaths() override
|
||||
|
|
|
@ -32,6 +32,14 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This command is stable before the others
|
||||
*/
|
||||
std::optional<ExperimentalFeature> experimentalFeature() override
|
||||
{
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::string description() override
|
||||
{
|
||||
return "upgrade Nix to the stable version declared in Nixpkgs";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue