diff --git a/changelog/addcommand.dd b/changelog/addcommand.dd index d3ee0bd..3a61406 100644 --- a/changelog/addcommand.dd +++ b/changelog/addcommand.dd @@ -1,6 +1,6 @@ Add Command -The `add` command adds a dependency to the dub.json/dub.sdl file. +The `add` command adds a dependency to the dub.json/dub.sdl recipe file. Running `dub add vibe-d` is equivalent to manually adding the following line to dub.sdl (X.Y.Z represents the latest version): dependency "vibe-d" version="~>X.Y.Z" @@ -9,3 +9,12 @@ "dependencies": { "vibe-d": "~>X.Y.Z" } + +It is also possible to add multiple packages at once and explicitly add a +simple $(LINK2 version specification,http://code.dlang.org/package-format?lang=json#version-specs) +for some of them. + +For example the command `dub add vibe-d='~>0.8.2' mir-algorithm=3.1.21` would +add the given 2 dependencies to the recipe file without querying the registry. + +Packages with and without version-specifier can be mixed in a single invocation. diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 759dc45..3286105 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1154,12 +1154,13 @@ this() { this.name = "add"; - this.argumentsPattern = ""; + this.argumentsPattern = "[=] []"; this.description = "Adds dependencies to the package file."; this.helpText = [ "Adds as dependencies.", "", - "Running \"dub add \" is the same as adding to the \"dependencies\" section in dub.json/dub.sdl." + "Running \"dub add \" is the same as adding to the \"dependencies\" section in dub.json/dub.sdl.", + "If no version is specified for one of the packages, dub will query the registry for the latest version." ]; } @@ -1175,8 +1176,18 @@ string filetype = existsFile(dub.rootPath ~ "dub.json") ? "json" : "sdl"; foreach (depname; free_args) { try { - auto ver = dub.getLatestVersion(depname); - auto dep = ver.isBranch ? Dependency(ver) : Dependency("~>" ~ ver.toString()); + Dependency dep; + auto parts = depname.findSplit("="); + if (!parts[1].empty) + { + depname = parts[0]; + dep = Dependency(parts[2]); + } + else + { + auto ver = dub.getLatestVersion(depname); + dep = ver.isBranch ? Dependency(ver) : Dependency("~>" ~ ver.toString()); + } auto pkg = readPackageRecipe(dub.rootPath ~ ("dub." ~ filetype)); pkg.buildSettings.dependencies[depname] = dep; diff --git a/test/issue1574-addcommand.sh b/test/issue1574-addcommand.sh index c2fb1c7..647a0fd 100755 --- a/test/issue1574-addcommand.sh +++ b/test/issue1574-addcommand.sh @@ -19,14 +19,12 @@ trap cleanup EXIT -$DUB init -n $tempDir +$DUB init --non-interactive --format=json $tempDir cd $tempDir echo "import gitcompatibledubpackage.subdir.file; void main(){}" > source/app.d - $DUB add gitcompatibledubpackage --skip-registry=all --registry=http://localhost:$PORT - -#if dub fails to compile, that means that the "import mir.math.common" did not work -if ! $DUB build; then - die "Add command failed" -fi +grep -q '"gitcompatibledubpackage"\s*:\s*"~>1\.0\.4"' dub.json +$DUB add gitcompatibledubpackage=1.0.2 non-existing-issue1574-pkg='~>9.8.7' --skip-registry=all +grep -q '"gitcompatibledubpackage"\s*:\s*"1\.0\.2"' dub.json +grep -q '"non-existing-issue1574-pkg"\s*:\s*"~>9\.8\.7"' dub.json