Skip to content

Commit d8a16d1

Browse files
HassanElDesoukyxedin
authored andcommitted
[tools] Improve error message and add output-filename as an option
1 parent e5c42e4 commit d8a16d1

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tools/swift-def-to-yaml-converter/swift-def-to-yaml-converter.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ static llvm::cl::opt<std::string>
5353
llvm::cl::desc("Directory for the output file"),
5454
llvm::cl::cat(Category));
5555

56+
static llvm::cl::opt<std::string>
57+
OutputFilename("output-filename",
58+
llvm::cl::desc("Filename for the output file"),
59+
llvm::cl::cat(Category));
60+
5661
} // namespace options
5762

5863
int main(int argc, char *argv[]) {
@@ -62,18 +67,25 @@ int main(int argc, char *argv[]) {
6267
llvm::cl::ParseCommandLineOptions(argc, argv,
6368
"Swift `.def` to YAML Converter\n");
6469

65-
// The default language for localization is English
66-
std::string defaultLocaleCode = "en";
67-
llvm::SmallString<128> LocalizedFilePath(options::OutputDirectory);
68-
llvm::sys::path::append(LocalizedFilePath, defaultLocaleCode);
69-
llvm::sys::path::replace_extension(LocalizedFilePath, ".yaml");
70+
llvm::SmallString<128> LocalizedFilePath;
71+
if (options::OutputFilename.empty()) {
72+
// The default language for localization is English
73+
std::string defaultLocaleCode = "en";
74+
LocalizedFilePath = options::OutputDirectory;
75+
llvm::sys::path::append(LocalizedFilePath, defaultLocaleCode);
76+
llvm::sys::path::replace_extension(LocalizedFilePath, ".yaml");
77+
} else {
78+
LocalizedFilePath = options::OutputFilename;
79+
}
7080

7181
std::error_code error;
7282
llvm::raw_fd_ostream OS(LocalizedFilePath.str(), error,
7383
llvm::sys::fs::F_None);
7484

7585
if (OS.has_error() || error) {
76-
llvm::errs() << LocalizedFilePath.str() << " does not exist\n";
86+
llvm::errs() << "Error has occurred while trying to write to "
87+
<< LocalizedFilePath.str()
88+
<< " with error code: " << error.message() << "\n";
7789
return EXIT_FAILURE;
7890
}
7991

0 commit comments

Comments
 (0)