Shaka Packager SDK
validate_flag.h
1 // Copyright 2014 Google LLC. 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 #ifndef PACKAGER_APP_VALIDATE_FLAG_H_
10 #define PACKAGER_APP_VALIDATE_FLAG_H_
11 
12 #include <string>
13 
14 #include <absl/strings/str_format.h>
15 
16 namespace shaka {
17 
20 void PrintError(const std::string& error_message);
21 
24 void PrintWarning(const std::string& warning_message);
25 
31 // and cannot be empty; If condition is false, then this flag should
32 // not be set.
36 template <class FlagType>
37 bool ValidateFlag(const char* flag_name,
38  const FlagType& flag_value,
39  bool condition,
40  bool optional,
41  const char* label) {
42  if (flag_value.empty()) {
43  if (!optional && condition) {
44  PrintError(absl::StrFormat("--%s is required if %s.", flag_name, label));
45  return false;
46  }
47  } else if (!condition) {
48  PrintError(absl::StrFormat("--%s should be specified only if %s.",
49  flag_name, label));
50  return false;
51  }
52  return true;
53 }
54 
55 } // namespace shaka
56 
57 #endif // PACKAGER_APP_VALIDATE_FLAG_H_
All the methods that are virtual are virtual for mocking.
Definition: crypto_flags.cc:66
void PrintWarning(const std::string &warning_message)
void PrintError(const std::string &error_message)
bool ValidateFlag(const char *flag_name, const FlagType &flag_value, bool condition, bool optional, const char *label)
Definition: validate_flag.h:37