Skip to content

Commit

Permalink
Stuctured command stability, reflect with --help
Browse files Browse the repository at this point in the history
Prior to this, there was an ad-hoc whitelist in `main.cc`. Now, every
command states its stability.

The big user-facing benefit is that we can now hide disabled unstable
command from `--help`, just as we hide similar such CLI arguments,
experimental features, and builtins.
  • Loading branch information
Ericson2314 committed Apr 2, 2023
1 parent 2ef99cd commit c09784e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/libutil/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ Strings argvToStrings(int argc, char * * argv)
return args;
}

std::optional<ExperimentalFeature> Command::experimentalFeature ()
{
return { Xp::NixCommand };
}

MultiCommand::MultiCommand(const Commands & commands_)
: commands(commands_)
{
Expand Down Expand Up @@ -403,6 +408,9 @@ nlohmann::json MultiCommand::toJSON()

for (auto & [name, commandFun] : commands) {
auto command = commandFun();
auto xp = command->experimentalFeature();
if (!experimentalFeatureSettings.isEnabled(xp))
continue;
auto j = command->toJSON();
auto cat = nlohmann::json::object();
cat["id"] = command->category();
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ struct Command : virtual public Args

static constexpr Category catDefault = 0;

virtual std::optional<ExperimentalFeature> experimentalFeature ();

virtual Category category() { return catDefault; }
};

Expand Down
5 changes: 5 additions & 0 deletions src/nix/doctor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ struct CmdDoctor : StoreCommand
{
bool success = true;

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";
Expand Down
9 changes: 5 additions & 4 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,9 @@ void mainWrapped(int argc, char * * argv)
NixArgs args;

if (argc == 2 && std::string(argv[1]) == "__dump-cli") {
experimentalFeatureSettings.experimentalFeatures = {
Xp::NixCommand,
};
logger->cout(args.dumpCli());
return;
}
Expand Down Expand Up @@ -420,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");
Expand Down
5 changes: 5 additions & 0 deletions src/nix/repl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ struct CmdRepl : RawInstallablesCommand
evalSettings.pureEval = false;
}

std::optional<ExperimentalFeature> experimentalFeature() override
{
return std::nullopt;
}

std::vector<std::string> files;

Strings getDefaultFlakeAttrPaths() override
Expand Down
5 changes: 5 additions & 0 deletions src/nix/upgrade-nix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
});
}

std::optional<ExperimentalFeature> experimentalFeature() override
{
return std::nullopt;
}

std::string description() override
{
return "upgrade Nix to the stable version declared in Nixpkgs";
Expand Down

0 comments on commit c09784e

Please sign in to comment.