Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input/Output dir options #248

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions dstep/Configuration.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the intention that both -O and -o are specified since this is a bool?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes


/// package name
@("package", "Use <package> as package name.")
Expand Down
8 changes: 4 additions & 4 deletions dstep/driver/Application.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 25 additions & 1 deletion dstep/driver/CommandLine.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -239,6 +261,8 @@ void showHelp (Configuration config, GetoptResult getoptResult)
auto customEntries = [
Entry("-o, --output <file>", "Write output to <file>."),
Entry("-o, --output <directory>", "Write all the files to <directory>, in case of multiple input files."),
Entry("-O, --output-to-dir", "Force write files to <directory>."),
Entry("-I, --input-from-dir", "Force to treat <input> 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 <language>.")];

Expand Down