Skip to content

Commit 0632c61

Browse files
committed
dub run <package> should search the registry on failure
1 parent 1b6aca1 commit 0632c61

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
Changelog
22
=========
33

4-
v1.8.1 - 2018-
4+
v1.9.0 (upcoming)
5+
-------------------
6+
7+
- `dub run` will now automatically fetch a package if it's not found locally [pull #1428][pull1428]
8+
9+
[pull1428][https://github.com/dlang/dub/pull/1428]
10+
11+
v1.8.1 - 2018-04-
512
-------------------
613

714
- Fixed a regression in 1.8.0 that caused linker files specified as `sourceFiles` to not get inherited properly - [issue #1408][issue1408], [pull #1409][issue1409]

source/dub/commandline.d

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,45 @@ class BuildCommand : GenerateCommand {
835835

836836
override int execute(Dub dub, string[] free_args, string[] app_args)
837837
{
838+
if (free_args.length >= 1) {
839+
auto package_name = free_args[0];
840+
auto pack = dub.packageManager.getFirstPackage(package_name);
841+
842+
if (!pack) {
843+
bool input(string caption, bool default_value = true) {
844+
writef("%s [%s]: ", caption, default_value ? "Y/n" : "y/N");
845+
auto inp = readln();
846+
string userInput = "y";
847+
if (inp.length > 1)
848+
userInput = inp[0 .. $ - 1].toLower;
849+
850+
switch (userInput) {
851+
case "no", "n", "0":
852+
return false;
853+
case "yes", "y", "1":
854+
default:
855+
return true;
856+
}
857+
}
858+
859+
// search for the package and filter for exact matches
860+
auto search = dub.searchPackages(package_name)
861+
.map!(tup => tup[1].find!(p => p.name == package_name))
862+
.filter!(ps => !ps.empty);
863+
if (search.empty)
864+
return 2;
865+
866+
auto p = search.front.front;
867+
writefln("%s wasn't found locally, but it's available online:", package_name);
868+
writefln("Description: %s", p.description);
869+
writefln("Version: %s", p.version_);
870+
871+
bool answer = input("Do you want to fetch %s?".format(package_name));
872+
auto dep = Dependency(p.version_);
873+
dub.fetch(package_name, dep, dub.defaultPlacementLocation, FetchOptions.none);
874+
}
875+
}
876+
838877
return super.execute(dub, free_args, app_args);
839878
}
840879
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -eu -o pipefail
4+
$DUB remove --version="*" gitcompatibledubpackage || true
5+
6+
echo "y" | $DUB run gitcompatibledubpackage -c exe | grep "Hello DUB"
7+
8+
$DUB remove gitcompatibledubpackage

0 commit comments

Comments
 (0)