libmain: undo accidental lix command stabilization

When external subcommand support landed, the `lix` binary gave
accidental access to nix3 CLI as well.

This was not the intended effect of this feature, we want to keep `lix`
as a namespace for a new redesign of the CLI (that has not started yet),
while giving that namespace for external subcommands.

To this end, we sever the nix3 CLI connection for the `lix` binary.

Fixes fj#508.

Change-Id: I13a0748bcbf87343c8e0e89439bd4af3a0ac3118
Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
Raito Bezarius
2025-03-28 21:08:52 +01:00
parent b52db5e7c1
commit a6adaab2bc
2 changed files with 48 additions and 37 deletions
+8 -1
View File
@@ -312,6 +312,10 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
ReceiveInterrupts receiveInterrupts; // FIXME: need better place for this
ErrorInfo::programName = baseNameOf(programName);
/* Lix command line is not yet stabilized.
* Explain that it is experimental and reserved for custom subcommands for now.
* */
bool onlyForSubcommands = ErrorInfo::programName == "lix";
std::string error = ANSI_RED "error:" ANSI_NORMAL " ";
try {
@@ -320,7 +324,10 @@ int handleExceptions(const std::string & programName, std::function<void()> fun)
return e.status;
} catch (UsageError & e) {
logError(e.info());
printError("Try '%1% --help' for more information.", programName);
if (onlyForSubcommands)
printError("'%1%' is reserved for external subcommands, is your subcommand available in the PATH?", programName);
else
printError("Try '%1% --help' for more information.", programName);
return 1;
} catch (BaseError & e) {
logError(e.info());
+40 -36
View File
@@ -202,7 +202,9 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
AsyncIoRoot & aio() override { return aio_; }
NixArgs(const std::string & programName, AsyncIoRoot & aio)
: MultiCommand(CommandRegistry::getCommandsFor({}), true)
/* NOTE: when using lix, the command map is empty as `lix-command` is not stabilized neither designed.
* `lix` is only used for external commands. */
: MultiCommand(programName == "lix" ? CommandMap() : CommandRegistry::getCommandsFor({}), programName == "lix")
, MixCommonArgs(programName)
, aio_(aio)
{
@@ -213,45 +215,47 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs, virtual RootArgs
categories[catUtility] = "Utility/scripting commands";
categories[catNixInstallation] = "Commands for upgrading or troubleshooting your Nix installation";
addFlag({
.longName = "help",
.description = "Show usage information.",
.category = miscCategory,
.handler = {[this]() { this->helpRequested = true; }},
});
if (programName != "lix") {
addFlag({
.longName = "help",
.description = "Show usage information.",
.category = miscCategory,
.handler = {[this]() { this->helpRequested = true; }},
});
addFlag({
.longName = "print-build-logs",
.shortName = 'L',
.description = "Print full build logs on standard error.",
.category = loggingCategory,
.handler = {[&]() { logger->setPrintBuildLogs(true); }},
.experimentalFeature = Xp::NixCommand,
});
addFlag({
.longName = "print-build-logs",
.shortName = 'L',
.description = "Print full build logs on standard error.",
.category = loggingCategory,
.handler = {[&]() { logger->setPrintBuildLogs(true); }},
.experimentalFeature = Xp::NixCommand,
});
addFlag({
.longName = "version",
.description = "Show version information.",
.category = miscCategory,
.handler = {[&]() { showVersion = true; }},
});
addFlag({
.longName = "version",
.description = "Show version information.",
.category = miscCategory,
.handler = {[&]() { showVersion = true; }},
});
addFlag({
.longName = "offline",
.aliases = {"no-net"}, // FIXME: remove
.description = "Disable substituters and consider all previously downloaded files up-to-date.",
.category = miscCategory,
.handler = {[&]() { useNet = false; }},
.experimentalFeature = Xp::NixCommand,
});
addFlag({
.longName = "offline",
.aliases = {"no-net"}, // FIXME: remove
.description = "Disable substituters and consider all previously downloaded files up-to-date.",
.category = miscCategory,
.handler = {[&]() { useNet = false; }},
.experimentalFeature = Xp::NixCommand,
});
addFlag({
.longName = "refresh",
.description = "Consider all previously downloaded files out-of-date.",
.category = miscCategory,
.handler = {[&]() { refresh = true; }},
.experimentalFeature = Xp::NixCommand,
});
addFlag({
.longName = "refresh",
.description = "Consider all previously downloaded files out-of-date.",
.category = miscCategory,
.handler = {[&]() { refresh = true; }},
.experimentalFeature = Xp::NixCommand,
});
}
}
std::map<std::string, std::vector<std::string>> aliases = {