diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 11c2150..de2d27e 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -17,7 +17,7 @@ import dub.package_; import dub.packagesupplier; import dub.project; -import dub.version_; +import dub.internal.utils : getDUBVersion; import std.algorithm; import std.array; @@ -35,7 +35,7 @@ int runDubCommandLine(string[] args) { - logDiagnostic("DUB version %s", dubVersion); + logDiagnostic("DUB version %s", getDUBVersion()); version(Windows){ // rdmd uses $TEMP to compute a temporary path. since cygwin substitutes backslashes @@ -957,6 +957,8 @@ writeln(`==============`); writeln(); writeOptions(common_args); + writeln(); + writefln("DUB version %s", getDUBVersion()); } private void showCommandHelp(Command cmd, CommandArgs args, CommandArgs common_args) @@ -981,6 +983,8 @@ writeln("=============="); writeln(); writeOptions(common_args); + writeln(); + writefln("DUB version %s", getDUBVersion()); } private void writeOptions(CommandArgs args) diff --git a/source/dub/internal/utils.d b/source/dub/internal/utils.d index 6e4cb7c..2cc14de 100644 --- a/source/dub/internal/utils.d +++ b/source/dub/internal/utils.d @@ -136,6 +136,22 @@ return download(url.toString()); } +/// Returns the current DUB version in semantic version format +string getDUBVersion() +{ + import dub.version_; + // convert version string to valid SemVer format + auto verstr = dubVersion; + if (verstr.startsWith("v")) verstr = verstr[1 .. $]; + auto parts = verstr.split("-"); + if (parts.length >= 3) { + // detect GIT commit suffix + if (parts[$-1].length == 8 && parts[$-1][1 .. $].isHexNumber() && parts[$-2].isNumber()) + verstr = parts[0 .. $-2].join("-") ~ "+" ~ parts[$-2 .. $].join("-"); + } + return verstr; +} + version(DubUseCurl) { private HTTP setupHTTPClient() { @@ -146,13 +162,7 @@ auto proxy = environment.get("http_proxy", null); if (proxy.length) conn.proxy = proxy; - // convert version string to valid SemVer format - auto verstr = dubVersion; - if (verstr.startsWith("v")) verstr = verstr[1 .. $]; - auto idx = verstr.indexOf("-"); - if (idx >= 0) verstr = verstr[0 .. idx] ~ "+" ~ verstr[idx+1 .. $].split("-").join("."); - - conn.addRequestHeader("User-Agent", "dub/"~verstr~" (std.net.curl; +https://github.com/rejectedsoftware/dub)"); + conn.addRequestHeader("User-Agent", "dub/"~getDUBVersion()~" (std.net.curl; +https://github.com/rejectedsoftware/dub)"); return conn; } } @@ -163,3 +173,23 @@ return str[3 ..$]; return str; } + +private bool isNumber(string str) { + foreach (ch; str) + switch (ch) { + case '0': .. case '9': break; + default: return false; + } + return true; +} + +private bool isHexNumber(string str) { + foreach (ch; str) + switch (ch) { + case '0': .. case '9': break; + case 'a': .. case 'f': break; + case 'A': .. case 'F': break; + default: return false; + } + return true; +} \ No newline at end of file