Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ability for specify version range for commandline commands #2056

Merged
merged 1 commit into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
All commands now accept a version specification

Before this release dub could only get an exact version for some commands
(`describe`, `generate`, `fetch`, etc...). All commands now accept a version specification,
such as can be found in `dub.json` / `dub.sdl`:

dub fetch 'foo@>0.2.0'
dub describe foo@'>=0.3.0 <1.0.0'

Note that commands such as `describe` will still not fetch from the network.
13 changes: 6 additions & 7 deletions source/dub/commandline.d
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,10 @@ abstract class PackageBuildCommand : Command {
protected void setupVersionPackage(Dub dub, string str_package_info, string default_build_type = "debug")
{
PackageAndVersion package_info = splitPackageName(str_package_info);
Version ver = package_info.version_.length ? Version(package_info.version_) : Version.unknown;
setupPackage(dub, package_info.name, default_build_type, ver);
setupPackage(dub, package_info.name, default_build_type, package_info.version_);
}

protected void setupPackage(Dub dub, string package_name, string default_build_type = "debug", Version ver = Version.unknown)
protected void setupPackage(Dub dub, string package_name, string default_build_type = "debug", string ver = "")
{
if (!m_compilerName.length) m_compilerName = dub.defaultCompiler;
if (!m_arch.length) m_arch = dub.defaultArchitecture;
Expand Down Expand Up @@ -1039,7 +1038,7 @@ abstract class PackageBuildCommand : Command {
}
}

private bool loadSpecificPackage(Dub dub, string package_name, Version ver)
private bool loadSpecificPackage(Dub dub, string package_name, string ver)
{
if (m_single) {
enforce(package_name.length, "Missing file name of single-file package.");
Expand All @@ -1061,12 +1060,12 @@ abstract class PackageBuildCommand : Command {

enforce(package_name.length, "No valid root package found - aborting.");

auto pack = ver.isUnknown
auto pack = ver == ""
? dub.packageManager.getLatestPackage(package_name)
: dub.packageManager.getPackage(package_name, ver);
: dub.packageManager.getBestPackage(package_name, ver);

enforce(pack, format!"Failed to find a package named '%s%s' locally."(package_name,
ver.isUnknown ? "" : "@" ~ ver.toString()
ver == "" ? "" : ("@" ~ ver)
));
logInfo("Building package %s in %s", pack.name, pack.path.toNativeString());
dub.loadPackage(pack);
Expand Down
7 changes: 7 additions & 0 deletions test/version-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ $DUB add-local "$CURR_DIR/version-spec/oldfoo"
[[ $($DUB describe [email protected] | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe [email protected] | grep path | head -n 1) == *"/oldfoo/"* ]]

[[ $($DUB describe foo@'<1.0.0' | grep path | head -n 1) == *"/oldfoo/"* ]]
[[ $($DUB describe foo@'>0.1.0' | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe foo@'>0.2.0' | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe foo@'<=0.2.0' | grep path | head -n 1) == *"/oldfoo/"* ]]
[[ $($DUB describe foo@'*' | grep path | head -n 1) == *"/newfoo/"* ]]
[[ $($DUB describe foo@'>0.0.1 <2.0.0' | grep path | head -n 1) == *"/newfoo/"* ]]

[[ $($DUB test foo | head -n 1) == *"/newfoo/" ]]
[[ $($DUB test [email protected] | head -n 1) == *"/newfoo/" ]]
[[ $($DUB test [email protected] | head -n 1) == *"/oldfoo/" ]]
Expand Down