Merge remote-tracking branch 'origin/master' into flakes

This commit is contained in:
Eelco Dolstra 2020-06-04 13:16:28 +02:00
commit f85606c431
6 changed files with 18 additions and 11 deletions

View File

@ -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))

View File

@ -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;

View File

@ -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)
{

View File

@ -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");

View File

@ -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

View File

@ -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