1 // Copyright (c) 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef QUICHE_COMMON_PLATFORM_API_QUICHE_COMMAND_LINE_FLAGS_H_
6 #define QUICHE_COMMON_PLATFORM_API_QUICHE_COMMAND_LINE_FLAGS_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "quiche_platform_impl/quiche_command_line_flags_impl.h"
12
13 // Define a command-line flag that can be automatically set via
14 // QuicheParseCommandLineFlags(). The macro has to be called in the .cc file of
15 // a unit test or the CLI tool reading the flag.
16 #define DEFINE_QUICHE_COMMAND_LINE_FLAG(type, name, default_value, help) \
17 DEFINE_QUICHE_COMMAND_LINE_FLAG_IMPL(type, name, default_value, help)
18
19 namespace quiche {
20
21 // The impl header must provide GetQuicheCommandLineFlag(), which takes
22 // PlatformSpecificFlag<T> variable defined by the macro above, and returns the
23 // flag value of type T.
24
25 // Parses command-line flags, setting flag variables defined using
26 // DEFINE_QUICHE_COMMAND_LINE_FLAG if they appear in the command line, and
27 // returning a list of any non-flag arguments specified in the command line. If
28 // the command line specifies '-h' or '--help', prints a usage message with flag
29 // descriptions to stdout and exits with status 0. If a flag has an unparsable
30 // value, writes an error message to stderr and exits with status 1.
QuicheParseCommandLineFlags(const char * usage,int argc,const char * const * argv)31 inline std::vector<std::string> QuicheParseCommandLineFlags(
32 const char* usage, int argc, const char* const* argv) {
33 return QuicheParseCommandLineFlagsImpl(usage, argc, argv);
34 }
35
36 // Prints a usage message with flag descriptions to stdout.
QuichePrintCommandLineFlagHelp(const char * usage)37 inline void QuichePrintCommandLineFlagHelp(const char* usage) {
38 QuichePrintCommandLineFlagHelpImpl(usage);
39 }
40
41 } // namespace quiche
42
43 #endif // QUICHE_COMMON_PLATFORM_API_QUICHE_COMMAND_LINE_FLAGS_H_
44