diff --git a/changelog/dub-fetch-shortcut.dd b/changelog/dub-fetch-shortcut.dd new file mode 100644 index 0000000..a912a36 --- /dev/null +++ b/changelog/dub-fetch-shortcut.dd @@ -0,0 +1,9 @@ +`dub fetch` now supports `@` as a shortcut + +`dub fetch @` is a shortcut for +`dub fetch --version=`: + +$(CONSOLE +> dub fetch gitcompatibledubpackage@1.0.4 +Fetching gitcompatibledubpackage 1.0.4... +) diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 0f7e1dc..a420aea 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -120,7 +120,7 @@ args[1] = args[1].setExtension(".d"); } } - + // special single-file package shebang syntax if (args.length >= 2 && args[1].endsWith(".d")) { args = args[0] ~ ["run", "-q", "--temp-build", "--single", args[1], "--"] ~ args[2 ..$]; @@ -1146,7 +1146,7 @@ this() { this.name = "add"; - this.argumentsPattern = "[=] []"; + this.argumentsPattern = "[@] []"; this.description = "Adds dependencies to the package file."; this.helpText = [ "Adds as dependencies.", @@ -1261,7 +1261,7 @@ this() { this.name = "fetch"; - this.argumentsPattern = ""; + this.argumentsPattern = "[@]"; this.description = "Manually retrieves and caches a package"; this.helpText = [ "Note: Use \"dub add \" if you just want to use a certain package as a dependency, you don't have to explicitly fetch packages.", @@ -1298,7 +1298,10 @@ FetchOptions fetchOpts; fetchOpts |= FetchOptions.forceBranchUpgrade; if (m_version.length) dub.fetch(name, Dependency(m_version), location, fetchOpts); - else { + else if (name.canFind("@", "=")) { + const parts = name.splitPackageName; + dub.fetch(parts.name, Dependency(parts.version_), location, fetchOpts); + } else { try { dub.fetch(name, Dependency(">=0.0.0"), location, fetchOpts); logInfo( @@ -2139,15 +2142,14 @@ private bool addDependency(Dub dub, ref PackageRecipe recipe, string depspec) { Dependency dep; - // split = - auto parts = depspec.findSplit("="); - auto depname = parts[0]; - if (!parts[1].empty) - dep = Dependency(parts[2]); + const parts = splitPackageName(depspec); + const depname = parts.name; + if (parts.version_) + dep = Dependency(parts.version_); else { try { - auto ver = dub.getLatestVersion(depname); + const ver = dub.getLatestVersion(depname); dep = ver.isBranch ? Dependency(ver) : Dependency("~>" ~ ver.toString()); } catch (Exception e) { logError("Could not find package '%s'.", depname); @@ -2159,3 +2161,27 @@ logInfo("Adding dependency %s %s", depname, dep.versionSpec); return true; } + +/* Split = and @ + into `name` and `version_`. */ +private auto splitPackageName(string packageName) +{ + struct PackageAndVersion + { + string name; + string version_; + } + + // split = + auto parts = packageName.split("="); + if (parts.length == 1) { + // support splitting @ too + parts = packageName.split("@"); + } + + PackageAndVersion p; + p.name = parts[0]; + if (parts.length > 1) + p.version_ = parts[1]; + return p; +} diff --git a/test/interactive-remove.sh b/test/interactive-remove.sh index 85053b8..d00a41c 100755 --- a/test/interactive-remove.sh +++ b/test/interactive-remove.sh @@ -23,7 +23,7 @@ die $LINENO 'Failed to remove all version of dub' fi $DUB fetch dub --version=1.9.0 && [ -d $HOME/.dub/packages/dub-1.9.0/dub ] -$DUB fetch dub --version=1.10.0 && [ -d $HOME/.dub/packages/dub-1.10.0/dub ] +$DUB fetch dub@1.10.0 && [ -d $HOME/.dub/packages/dub-1.10.0/dub ] # is non-interactive with --version= $DUB remove dub --version=\* if [ -d $HOME/.dub/packages/dub-1.9.0/dub ] || [ -d $HOME/.dub/packages/dub-1.10.0/dub ]; then diff --git a/test/issue1574-addcommand.sh b/test/issue1574-addcommand.sh index 002acb1..dddedca 100755 --- a/test/issue1574-addcommand.sh +++ b/test/issue1574-addcommand.sh @@ -28,7 +28,7 @@ $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 -if $DUB add foo=1.2.3 gitcompatibledubpackage='~>a.b.c' --skip-registry=all; then +if $DUB add foo@1.2.3 gitcompatibledubpackage='~>a.b.c' --skip-registry=all; then die $LINENO 'Adding non-semver spec should error' fi if grep -q '"foo"' dub.json; then