DASH Media Packaging SDK
 All Classes Namespaces Functions Variables Typedefs
validate_flag.cc
1 // Copyright 2014 Google Inc. All rights reserved.
2 //
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file or at
5 // https://developers.google.com/open-source/licenses/bsd
6 //
7 // Flag validation help functions.
8 
9 #include "packager/app/validate_flag.h"
10 
11 #include <stdio.h>
12 
13 #include "packager/base/strings/stringprintf.h"
14 
15 namespace edash_packager {
16 
17 bool ValidateFlag(const char* flag_name,
18  const std::string& flag_value,
19  bool condition,
20  bool optional,
21  const char* label) {
22  if (flag_value.empty()) {
23  if (!optional && condition) {
24  PrintError(
25  base::StringPrintf("--%s is required if %s.", flag_name, label));
26  return false;
27  }
28  } else if (!condition) {
29  PrintError(base::StringPrintf(
30  "--%s should be specified only if %s.", flag_name, label));
31  return false;
32  }
33  return true;
34 }
35 
36 void PrintError(const std::string& error_message) {
37  fprintf(stderr, "ERROR: %s\n", error_message.c_str());
38 }
39 
40 } // namespace edash_packager
bool ValidateFlag(const char *flag_name, const std::string &flag_value, bool condition, bool optional, const char *label)
void PrintError(const std::string &error_message)