diff --git a/source/dub/commandline.d b/source/dub/commandline.d index bb8df3f..9a3135f 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -411,10 +411,19 @@ return inp.length > 1 ? inp[0 .. $-1] : default_value; } - void depCallback(ref PackageRecipe p) { + void depCallback(ref PackageRecipe p, ref PackageFormat fmt) { if (m_nonInteractive) return; - auto fmt = input("Package recipe format (sdl/json)", m_format.to!string); + while (true) { + string rawfmt = input("Package recipe format (sdl/json)", fmt.to!string); + if (!rawfmt.length) break; + try { + fmt = rawfmt.to!PackageFormat; + break; + } catch (Exception) { + logError("Invalid format, \""~rawfmt~"\", enter either \"sdl\" or \"json\"."); + } + } auto author = p.authors.join(", "); p.name = input("Name", p.name); p.description = input("Description", p.description); diff --git a/source/dub/dub.d b/source/dub/dub.d index eec2ce1..c513864 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -745,7 +745,9 @@ else return vers[$-1]; } - void createEmptyPackage(Path path, string[] deps, string type, PackageFormat format = PackageFormat.sdl, scope void delegate(ref PackageRecipe) recipe_callback = null) + void createEmptyPackage(Path path, string[] deps, string type, + PackageFormat format = PackageFormat.sdl, + scope void delegate(ref PackageRecipe, ref PackageFormat) recipe_callback = null) { if (!path.absolute) path = m_rootPath ~ path; path.normalize(); diff --git a/source/dub/init.d b/source/dub/init.d index aff77c4..7d8d98b 100644 --- a/source/dub/init.d +++ b/source/dub/init.d @@ -20,7 +20,7 @@ import std.process; import std.string; -void initPackage(Path root_path, string[string] deps, string type, PackageFormat format, scope void delegate(ref PackageRecipe) recipe_callback = null) +void initPackage(Path root_path, string[string] deps, string type, PackageFormat format, scope void delegate(ref PackageRecipe, ref PackageFormat) recipe_callback = null) { import std.conv : to; import dub.recipe.io : writePackageRecipe; @@ -62,7 +62,7 @@ case "deimos": initDeimosPackage(root_path, p); break; } - if (recipe_callback) recipe_callback(p); + if (recipe_callback) recipe_callback(p, format); writePackageRecipe(root_path ~ ("dub."~format.to!string), p); writeGitignore(root_path); }