Skip to content

Commit

Permalink
Make 'nix dev-shell' a deprecated alias for 'nix develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Jun 4, 2020
1 parent 61e3d59 commit 0f44b60
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/libutil/args.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,10 +217,15 @@ MultiCommand::MultiCommand(const Commands & commands)
{
expectedArgs.push_back(ExpectedArg{"command", 1, true, [=](std::vector<std::string> ss) {
assert(!command);
auto i = commands.find(ss[0]);
auto cmd = ss[0];
if (auto alias = get(deprecatedAliases, cmd)) {
warn("'%s' is a deprecated alias for '%s'", cmd, *alias);
cmd = *alias;
}
auto i = commands.find(cmd);
if (i == commands.end())
throw UsageError("'%s' is not a recognised command", ss[0]);
command = {ss[0], i->second()};
throw UsageError("'%s' is not a recognised command", cmd);
command = {cmd, i->second()};
}});

categories[Command::catDefault] = "Available commands";
Expand Down
2 changes: 2 additions & 0 deletions src/libutil/args.hh
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,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;

Expand Down
3 changes: 1 addition & 2 deletions src/libutil/util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +459,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)
{
Expand Down
2 changes: 2 additions & 0 deletions src/nix/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0f44b60

Please sign in to comment.