From a6adaab2bcb87ce5f71ad6c78dd6c03c920f159a Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Fri, 28 Mar 2025 21:08:02 +0100 Subject: [PATCH] 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 --- lix/libmain/shared.cc | 9 ++++- lix/nix/main.cc | 76 +++++++++++++++++++++++-------------------- 2 files changed, 48 insertions(+), 37 deletions(-) diff --git a/lix/libmain/shared.cc b/lix/libmain/shared.cc index 184c6bec9..04cf476f7 100644 --- a/lix/libmain/shared.cc +++ b/lix/libmain/shared.cc @@ -312,6 +312,10 @@ int handleExceptions(const std::string & programName, std::function 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 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()); diff --git a/lix/nix/main.cc b/lix/nix/main.cc index b22f13217..819da09bb 100644 --- a/lix/nix/main.cc +++ b/lix/nix/main.cc @@ -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> aliases = {