diff --git a/dstep/Configuration.d b/dstep/Configuration.d index 3ea9ec1e..53cef86c 100644 --- a/dstep/Configuration.d +++ b/dstep/Configuration.d @@ -20,6 +20,9 @@ struct Configuration /// array of file names to translate to D string[] inputFiles; + /// in case if there are many input files in one dir + bool isInputFromDir; + /// expected programming language of input files Language language; @@ -34,8 +37,11 @@ struct Configuration /// array of parameters needed to be forwarded to clang driver string[] clangParams; - /// output file name or folder (in case there are many input files) - string output; + /// output file name or folder + string outputPath; + + /// in case there are many input files or dir output option provided + bool isOutputToDir; /// package name @("package", "Use as package name.") diff --git a/dstep/driver/Application.d b/dstep/driver/Application.d index 45ef1caa..2e4ccee3 100644 --- a/dstep/driver/Application.d +++ b/dstep/driver/Application.d @@ -125,16 +125,16 @@ class Application // when only one input file is supplied, -o argument is // interpreted as file path, otherwise as base directory path - if (inputFiles.length == 1) + if (!config.isOutputToDir) { - return [config.output.empty + return [config.outputPath.empty ? makeDefaultOutputFile(inputFiles.front, false) - : config.output]; + : config.outputPath]; } else { alias fmap = file => Path.buildPath( - config.output, + config.outputPath, makeDefaultOutputFile(file, false)); return inputFiles.map!fmap.array; diff --git a/dstep/driver/CommandLine.d b/dstep/driver/CommandLine.d index 346eca67..7bb64d4d 100644 --- a/dstep/driver/CommandLine.d +++ b/dstep/driver/CommandLine.d @@ -67,7 +67,9 @@ auto parseCommandLine(string[] args) args, std.getopt.config.passThrough, std.getopt.config.caseSensitive, - "output|o", &config.output, + "input-from-dir|I", &config.isInputFromDir, + "output|o", &config.outputPath, + "output-to-dir|O", &config.isOutputToDir, "objective-c", &forceObjectiveC, "language|x", &parseLanguage, makeGetOptArgs!config); @@ -84,6 +86,26 @@ auto parseCommandLine(string[] args) config.inputFiles ~= arg; } + if(config.isInputFromDir) + { + import std.exception : enforce; + import std.file; + import std.algorithm; + import std.algorithm.iteration; + import std.array; + + enforce!DStepException(config.inputFiles.length == 1, + "dstep: error: must supply only one input directory\n"); + + config.inputFiles = dirEntries(config.inputFiles[0], SpanMode.depth) + .filter!(f => f.name.endsWith(".h")) + .map!(a => a.name) + .array; + } + + if(config.isInputFromDir || config.inputFiles.length > 1) + config.isOutputToDir = true; + // Post-processing of CLI import std.algorithm : canFind; @@ -239,6 +261,8 @@ void showHelp (Configuration config, GetoptResult getoptResult) auto customEntries = [ Entry("-o, --output ", "Write output to ."), Entry("-o, --output ", "Write all the files to , in case of multiple input files."), + Entry("-O, --output-to-dir", "Force write files to ."), + Entry("-I, --input-from-dir", "Force to treat as directory. Reads only *.h files."), Entry("-ObjC, --objective-c", "Treat source input file as Objective-C input."), Entry("-x, --language", "Treat subsequent input files as having type .")];