diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 0aa07b3..cf789b6 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1810,6 +1810,7 @@ class ConvertCommand : Command { private { string m_format; + bool m_stdout; } this() @@ -1827,6 +1828,7 @@ override void prepare(scope CommandArgs args) { args.getopt("f|format", &m_format, ["Specifies the target package recipe format. Possible values:", " json, sdl"]); + args.getopt("s|stdout", &m_stdout, ["Outputs the converted package recipe to stdout instead of writing to disk."]); } override int execute(Dub dub, string[] free_args, string[] app_args) @@ -1835,7 +1837,7 @@ enforceUsage(free_args.length == 0, "Unexpected arguments: "~free_args.join(" ")); enforceUsage(m_format.length > 0, "Missing target format file extension (--format=...)."); if (!loadCwdPackage(dub, true)) return 1; - dub.convertRecipe(m_format); + dub.convertRecipe(m_format, m_stdout); return 0; } } diff --git a/source/dub/dub.d b/source/dub/dub.d index 8fc1f88..2d31988 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -986,11 +986,19 @@ Params: destination_file_ext = The file extension matching the desired format. Possible values are "json" or "sdl". + print_only = Print the converted recipe instead of writing to disk */ - void convertRecipe(string destination_file_ext) + void convertRecipe(string destination_file_ext, bool print_only = false) { import std.path : extension; - import dub.recipe.io : writePackageRecipe; + import std.stdio : stdout; + import dub.recipe.io : serializePackageRecipe, writePackageRecipe; + + if (print_only) { + auto dst = stdout.lockingTextWriter; + serializePackageRecipe(dst, m_project.rootPackage.rawRecipe, "dub."~destination_file_ext); + return; + } auto srcfile = m_project.rootPackage.recipePath; auto srcext = srcfile[$-1].toString().extension;