diff options
-rw-r--r-- | src/libutil/args.cc | 4 | ||||
-rw-r--r-- | src/libutil/args.hh | 2 | ||||
-rw-r--r-- | src/libutil/util.hh | 3 | ||||
-rw-r--r-- | src/nix/develop.cc (renamed from src/nix/dev-shell.cc) | 16 | ||||
-rw-r--r-- | src/nix/local.mk | 2 | ||||
-rw-r--r-- | src/nix/main.cc | 2 |
6 files changed, 18 insertions, 11 deletions
diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 8667bd450..24b8ca66b 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -303,6 +303,10 @@ MultiCommand::MultiCommand(const Commands & commands) .optional = true, .handler = {[=](std::string s) { assert(!command); + if (auto alias = get(deprecatedAliases, s)) { + warn("'%s' is a deprecated alias for '%s'", s, *alias); + s = *alias; + } if (auto prefix = needsCompletion(s)) { for (auto & [name, command] : commands) if (hasPrefix(name, *prefix)) diff --git a/src/libutil/args.hh b/src/libutil/args.hh index 405ec3d47..59541df99 100644 --- a/src/libutil/args.hh +++ b/src/libutil/args.hh @@ -248,6 +248,8 @@ public: std::map<Command::Category, std::string> categories; + std::map<std::string, std::string> deprecatedAliases; + // Selected command, if any. std::optional<std::pair<std::string, ref<Command>>> command; diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 52ca804a0..194a3ed4a 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -463,8 +463,7 @@ string base64Encode(const string & s); string base64Decode(const string & s); -/* Get a value for the specified key from an associate container, or a - default value if the key doesn't exist. */ +/* Get a value for the specified key from an associate container. */ template <class T> std::optional<typename T::mapped_type> get(const T & map, const typename T::key_type & key) { diff --git a/src/nix/dev-shell.cc b/src/nix/develop.cc index 53d2e4e25..59fcc15f4 100644 --- a/src/nix/dev-shell.cc +++ b/src/nix/develop.cc @@ -110,7 +110,7 @@ StorePath getDerivationEnvironment(ref<Store> store, const StorePath & drvPath) auto builder = baseNameOf(drv.builder); if (builder != "bash") - throw Error("'nix dev-shell' only works on derivations that use 'bash' as their builder"); + throw Error("'nix develop' only works on derivations that use 'bash' as their builder"); auto getEnvShPath = store->addTextToStore("get-env.sh", getEnvSh, {}); @@ -236,11 +236,11 @@ struct Common : InstallableCommand, MixProfile } }; -struct CmdDevShell : Common, MixEnvironment +struct CmdDevelop : Common, MixEnvironment { std::vector<std::string> command; - CmdDevShell() + CmdDevelop() { addFlag({ .longName = "command", @@ -264,19 +264,19 @@ struct CmdDevShell : Common, MixEnvironment return { Example{ "To get the build environment of GNU hello:", - "nix dev-shell nixpkgs#hello" + "nix develop nixpkgs#hello" }, Example{ "To get the build environment of the default package of flake in the current directory:", - "nix dev-shell" + "nix develop" }, Example{ "To store the build environment in a profile:", - "nix dev-shell --profile /tmp/my-shell nixpkgs#hello" + "nix develop --profile /tmp/my-shell nixpkgs#hello" }, Example{ "To use a build environment previously recorded in a profile:", - "nix dev-shell /tmp/my-shell" + "nix develop /tmp/my-shell" }, }; } @@ -351,4 +351,4 @@ struct CmdPrintDevEnv : Common }; static auto r1 = registerCommand<CmdPrintDevEnv>("print-dev-env"); -static auto r2 = registerCommand<CmdDevShell>("dev-shell"); +static auto r2 = registerCommand<CmdDevelop>("develop"); diff --git a/src/nix/local.mk b/src/nix/local.mk index 808d645cf..9ed55f1f6 100644 --- a/src/nix/local.mk +++ b/src/nix/local.mk @@ -28,6 +28,6 @@ $(eval $(call install-symlink, $(bindir)/nix, $(libexecdir)/nix/build-remote)) src/nix-env/user-env.cc: src/nix-env/buildenv.nix.gen.hh -src/nix/dev-shell.cc: src/nix/get-env.sh.gen.hh +src/nix/develop.cc: src/nix/get-env.sh.gen.hh $(d)/flake.cc: $(d)/flake-template.nix.gen.hh diff --git a/src/nix/main.cc b/src/nix/main.cc index 94fd33244..936674354 100644 --- a/src/nix/main.cc +++ b/src/nix/main.cc @@ -110,6 +110,8 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs .description = "consider all previously downloaded files out-of-date", .handler = {[&]() { refresh = true; }}, }); + + deprecatedAliases.insert({"dev-shell", "develop"}); } void printFlags(std::ostream & out) override |