Просмотр исходного кода

show help if protoc is called without any arguments, pre-empts -h and --help to show a useful message instead of just 'Missing input file.'

Dennis Cappendijk 8 лет назад
Родитель
Сommit
3b227611d5
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      src/google/protobuf/compiler/command_line_interface.cc

+ 6 - 0
src/google/protobuf/compiler/command_line_interface.cc

@@ -1012,6 +1012,12 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) {
     arguments.push_back(argv[i]);
     arguments.push_back(argv[i]);
   }
   }
 
 
+  // if no arguments are given, show help
+  if(arguments.empty()) {
+    PrintHelpText();
+    return PARSE_ARGUMENT_DONE_AND_EXIT;  // Exit without running compiler.
+  }
+
   // Iterate through all arguments and parse them.
   // Iterate through all arguments and parse them.
   for (int i = 0; i < arguments.size(); ++i) {
   for (int i = 0; i < arguments.size(); ++i) {
     string name, value;
     string name, value;