From 56f95ecf9922df29be1b5929e6e39d92dce1a0e6 Mon Sep 17 00:00:00 2001 From: hyunho Date: Fri, 21 Feb 2020 11:30:19 +0900 Subject: [PATCH] Add more details for the tidlc error cases Change-Id: Ib31d4080022f11ec1df3da83c4097cac051f3505 Signed-off-by: hyunho --- idlc/main.cc | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/idlc/main.cc b/idlc/main.cc index 2c405dd..4e19baf 100644 --- a/idlc/main.cc +++ b/idlc/main.cc @@ -68,6 +68,7 @@ class Options { void PrintUsage(); void PrintVersion(); + void PrintSample(); private: bool isProxy_; @@ -109,6 +110,10 @@ void Options::PrintVersion() { std::cerr << "tidlc " << FULLVER << std::endl; } +void Options::PrintSample() { + std::cerr << "tidlc -p -l C++ -i test.tidl -o CppTestProxy " << std::endl; +} + std::unique_ptr Options::Parse(int argc, char** argv) { int cmd[CMD_MAX] = { 0, }; int opt[OPT_MAX] = { 0, }; @@ -187,11 +192,31 @@ std::unique_ptr Options::Parse(int argc, char** argv) { return std::unique_ptr(nullptr); } - if (cmd[CMD_HELP] || (!cmd[CMD_PROXY] && !cmd[CMD_STUB]) || - !opt[OPT_LANGUAGE] || !opt[OPT_INPUT] || - !opt[OPT_OUTPUT]) { + if (cmd[CMD_HELP]) { options->PrintUsage(); return std::unique_ptr(nullptr); + } else if (!cmd[CMD_PROXY] && !cmd[CMD_STUB]) { + std::cerr << "Stub or proxy must be specified." << std::endl; + options->PrintSample(); + return std::unique_ptr(nullptr); + } else if (!opt[OPT_LANGUAGE]) { + std::cerr << "Select a language (C, C++, C#).." << std::endl; + options->PrintSample(); + return std::unique_ptr(nullptr); + } else if (!opt[OPT_INPUT]) { + std::cerr << "No input file." << std::endl; + options->PrintSample(); + return std::unique_ptr(nullptr); + } else if (opt[OPT_INPUT]) { + std::ifstream in_file(options->input_.c_str()); + if (!in_file.good()) { + std::cerr << "Not exist input file." << std::endl; + return std::unique_ptr(nullptr); + } + } else if (!opt[OPT_OUTPUT]) { + std::cerr << "No out file." << std::endl; + options->PrintSample(); + return std::unique_ptr(nullptr); } options->isProxy_ = cmd[CMD_PROXY] ? true : false; -- 2.7.4