diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 3b00dd6..ad71aab 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -749,14 +749,12 @@ private { bool m_importPaths = false; bool m_stringImportPaths = false; + bool m_dataList = false; string[] m_data; - string m_dataFormat; } this() { - m_dataFormat = m_compilerName; // Default compiler - this.name = "describe"; this.argumentsPattern = "[<package>]"; this.description = "Prints a JSON description of the project and its dependencies"; @@ -768,7 +766,7 @@ "All usual options that are also used for build/run/generate apply.", "", "When --data=VALUE is supplied, specific build settings for a project ", - "will be printed instead (by default, line-by-line).", + "will be printed instead (by default, formatted for the current compiler).", "", "The --data=VALUE option can be specified multiple times to retrieve " "several pieces of information at once. The data will be output in " @@ -776,13 +774,16 @@ "", "The accepted values for --data=VALUE are:", "", - "target-type, target-path, target-name, working-directory, " "main-source-file, dflags, lflags, libs, lib-files, source-files, " - "copy-files, versions, debug-versions, import-paths, " - "string-import-paths, import-files, string-import-files, " - "pre-generate-commands, post-generate-commands, " - "pre-build-commands, post-build-commands, " - "requirements, options", + "versions, debug-versions, import-paths, string-import-paths, " + "import-files, options", + "", + "The following are also accepted by --data if --data-list is used:", + "", + "target-type, target-path, target-name, working-directory, " + "copy-files, string-import-files, pre-generate-commands," + "post-generate-commands, pre-build-commands, post-build-commands, " + "requirements", ]; } @@ -791,11 +792,11 @@ super.prepare(args); args.getopt("import-paths", &m_importPaths, [ - "Shortcut for --data=import-paths --data-format=list" + "Shortcut for --data=import-paths --data-list" ]); args.getopt("string-import-paths", &m_stringImportPaths, [ - "Shortcut for --data=string-import-paths --data-format=list" + "Shortcut for --data=string-import-paths --data-list" ]); args.getopt("data", &m_data, [ @@ -804,10 +805,9 @@ "above for more details and accepted possibilities for VALUE." ]); - args.getopt("data-format", &m_dataFormat, [ - "Specifies the output format for --data. Possible values:", - " "~["list", "dmd", "gdc", "ldc", "gdmd", "ldmd"].join(", "), - "Default value: "~m_dataFormat, + args.getopt("data-list", &m_dataList, [ + "Output --data information in list format (line-by-line), instead "~ + "of formatting for a compiler command line.", ]); } @@ -842,7 +842,7 @@ } else if (m_stringImportPaths) { dub.listStringImportPaths(m_buildPlatform, config, m_buildType); } else if (m_data) { - dub.listProjectData(m_buildPlatform, config, m_buildType, m_data, m_dataFormat); + dub.listProjectData(m_buildPlatform, config, m_buildType, m_data, m_dataList? null : m_compiler); } else { auto desc = dub.project.describe(m_buildPlatform, config, m_buildType); writeln(desc.serializeToPrettyJson()); diff --git a/source/dub/dub.d b/source/dub/dub.d index ae319ce..cd2d1a4 100644 --- a/source/dub/dub.d +++ b/source/dub/dub.d @@ -439,11 +439,11 @@ } } - void listProjectData(BuildPlatform platform, string config, string buildType, string[] requestedData, string format) + void listProjectData(BuildPlatform platform, string config, string buildType, string[] requestedData, Compiler formattingCompiler) { import std.stdio; - foreach(data; m_project.listBuildSettings(platform, config, buildType, requestedData, format)) { + foreach(data; m_project.listBuildSettings(platform, config, buildType, requestedData, formattingCompiler)) { writeln(data); } } diff --git a/source/dub/project.d b/source/dub/project.d index 9be594f..26d53cd 100644 --- a/source/dub/project.d +++ b/source/dub/project.d @@ -888,7 +888,7 @@ } /// Outputs requested data for the project, optionally including its dependencies. - string[] listBuildSettings(BuildPlatform platform, string config, string buildType, string[] requestedData, string format) + string[] listBuildSettings(BuildPlatform platform, string config, string buildType, string[] requestedData, Compiler formattingCompiler) { auto projectDescription = describe(platform, config, buildType); auto configs = getPackageConfigs(platform, config); @@ -914,28 +914,23 @@ } // Genrate results - if (format == "list") + if (formattingCompiler) { + // Format for a compiler + return [ + requestedData + .map!(dataName => listBuildSetting(platform, configs, projectDescription, dataName, formattingCompiler)) + .join().join(" ") + ]; + } + else + { + // Format list-style return requestedData .map!(dataName => listBuildSetting(platform, configs, projectDescription, dataName, null)) .joiner([""]) // Blank line between each type of requestedData .array(); } - else - { - Compiler compiler; - try - compiler = getCompiler(format); - catch - enforce(false, "--data-format="~format~ - " is not a valid option. See 'dub describe --help' for accepted --data-format= values."); - - return [ - requestedData - .map!(dataName => listBuildSetting(platform, configs, projectDescription, dataName, compiler)) - .join().join(" ") - ]; - } } /// Outputs the import paths for the project, including its dependencies. diff --git a/test/4-describe-data-dmd.sh b/test/4-describe-data-dmd.sh index 00b9c18..5806fcd 100755 --- a/test/4-describe-data-dmd.sh +++ b/test/4-describe-data-dmd.sh @@ -12,7 +12,7 @@ trap cleanup EXIT -if ! $DUB describe --compiler=$COMPILER --data-format=dmd \ +if ! $DUB describe --compiler=dmd \ --data=main-source-file \ --data=dflags \ --data=lflags \ diff --git a/test/4-describe-data-list.sh b/test/4-describe-data-list.sh index 36c689b..d82cef1 100755 --- a/test/4-describe-data-list.sh +++ b/test/4-describe-data-list.sh @@ -12,7 +12,7 @@ trap cleanup EXIT -if ! $DUB describe --compiler=$COMPILER --data-format=list \ +if ! $DUB describe --compiler=$COMPILER --data-list \ --data=target-type \ --data=target-path \ --data=target-name \