diff --git a/source/dub/commandline.d b/source/dub/commandline.d index a3d9c08..91120c7 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -560,7 +560,8 @@ args.getopt("verror", &verror, ["Only print errors"]); args.getopt("vquiet", &vquiet, ["Print no messages"]); args.getopt("cache", &placementLocation, ["Puts any fetched packages in the specified location [local|system|user]."]); - args.getopt("version", &version_, ["Print the application version"]); + + version_ = args.hasAppVersion; } } @@ -604,6 +605,14 @@ */ @property bool hasAppArgs() { return m_appArgs.length > 0; } + + /** Checks if the `--version` argument is present. + + Returns: + true if the application version argument is present + */ + @property bool hasAppVersion() { return m_args.length > 1 && m_args[1] == "--version"; } + /** Returns the list of app args. The app args are provided after the `--` argument. @@ -669,6 +678,21 @@ } } +/// It should not find the app version for an empty arg list +unittest { + assert(new CommandArgs([]).hasAppVersion == false); +} + +/// It should find the app version when `--version` is the first arg +unittest { + assert(new CommandArgs(["--version"]).hasAppVersion == true); +} + +/// It should not find the app version when `--version` is the second arg +unittest { + assert(new CommandArgs(["a", "--version"]).hasAppVersion == false); +} + /// It returns an empty app arg list when `--` arg is missing unittest { assert(new CommandArgs(["1", "2"]).appArgs == []);