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:
+15
-2
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user