diff --git a/source/dub/commandline.d b/source/dub/commandline.d index bd947f4..43defa6 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -57,6 +57,7 @@ CommandGroup("Package management", new FetchCommand, new InstallCommand, + new AddCommand, new RemoveCommand, new UninstallCommand, new UpgradeCommand, @@ -1125,9 +1126,50 @@ /******************************************************************************/ -/* FETCH / REMOVE / UPGRADE */ +/* FETCH / ADD / REMOVE / UPGRADE */ /******************************************************************************/ +class AddCommand : Command { + this() + { + this.name = "add"; + this.argumentsPattern = ""; + this.description = "Adds a package to the package file."; + this.helpText = [ + "Adds as dependencies to the package.", + "", + "Running \"dub add \" is the same as adding to the \"dependencies\" section in dub.json/dub.sdl." + ]; + } + + override void prepare(scope CommandArgs args) {} + + override int execute(Dub dub, string[] free_args, string[] app_args) + { + import dub.recipe.io : readPackageRecipe, writePackageRecipe; + enforceUsage(free_args.length != 0, "Expected one or more arguments."); + enforceUsage(app_args.length == 0, "Unexpected application arguments."); + + foreach (depname; free_args) { + try { + auto ver = dub.getLatestVersion(depname); + auto dep = ver.isBranch ? Dependency(ver) : Dependency("~>" ~ ver.toString()); + auto pkg = readPackageRecipe(dub.rootPath ~ "dub.json").clone();//TODO: detect if dub.json or dub.sdl + + pkg.buildSettings.dependencies[depname] = dep; + writePackageRecipe(dub.rootPath ~ "dub.json", pkg);//TODO: detect if dub.json or dub.sdl + + logInfo("Added dependency %s %s", depname, dep.versionSpec); + } catch (Exception e) { + logError("Could not find package '%s'.", depname); + logDebug("Full error: %s", e.toString().sanitize); + } + } + + return 0; + } +} + class UpgradeCommand : Command { private { bool m_prerelease = false; diff --git a/source/dub/version_.d b/source/dub/version_.d index 2d36105..7a87f04 100644 --- a/source/dub/version_.d +++ b/source/dub/version_.d @@ -1,2 +1,2 @@ module dub.version_; -enum dubVersion = "v1.12.0"; +enum dubVersion = "v1.12.0-20-gbd67301";