xref: /aosp_15_r20/external/abseil-cpp/absl/flags/internal/parse.h (revision 9356374a3709195abf420251b3e825997ff56c0f)
1*9356374aSAndroid Build Coastguard Worker //
2*9356374aSAndroid Build Coastguard Worker // Copyright 2019 The Abseil Authors.
3*9356374aSAndroid Build Coastguard Worker //
4*9356374aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License");
5*9356374aSAndroid Build Coastguard Worker // you may not use this file except in compliance with the License.
6*9356374aSAndroid Build Coastguard Worker // You may obtain a copy of the License at
7*9356374aSAndroid Build Coastguard Worker //
8*9356374aSAndroid Build Coastguard Worker //      https://www.apache.org/licenses/LICENSE-2.0
9*9356374aSAndroid Build Coastguard Worker //
10*9356374aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
11*9356374aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS,
12*9356374aSAndroid Build Coastguard Worker // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*9356374aSAndroid Build Coastguard Worker // See the License for the specific language governing permissions and
14*9356374aSAndroid Build Coastguard Worker // limitations under the License.
15*9356374aSAndroid Build Coastguard Worker 
16*9356374aSAndroid Build Coastguard Worker #ifndef ABSL_FLAGS_INTERNAL_PARSE_H_
17*9356374aSAndroid Build Coastguard Worker #define ABSL_FLAGS_INTERNAL_PARSE_H_
18*9356374aSAndroid Build Coastguard Worker 
19*9356374aSAndroid Build Coastguard Worker #include <iostream>
20*9356374aSAndroid Build Coastguard Worker #include <ostream>
21*9356374aSAndroid Build Coastguard Worker #include <string>
22*9356374aSAndroid Build Coastguard Worker #include <vector>
23*9356374aSAndroid Build Coastguard Worker 
24*9356374aSAndroid Build Coastguard Worker #include "absl/base/config.h"
25*9356374aSAndroid Build Coastguard Worker #include "absl/flags/declare.h"
26*9356374aSAndroid Build Coastguard Worker #include "absl/flags/internal/usage.h"
27*9356374aSAndroid Build Coastguard Worker #include "absl/strings/string_view.h"
28*9356374aSAndroid Build Coastguard Worker 
29*9356374aSAndroid Build Coastguard Worker ABSL_DECLARE_FLAG(std::vector<std::string>, flagfile);
30*9356374aSAndroid Build Coastguard Worker ABSL_DECLARE_FLAG(std::vector<std::string>, fromenv);
31*9356374aSAndroid Build Coastguard Worker ABSL_DECLARE_FLAG(std::vector<std::string>, tryfromenv);
32*9356374aSAndroid Build Coastguard Worker ABSL_DECLARE_FLAG(std::vector<std::string>, undefok);
33*9356374aSAndroid Build Coastguard Worker 
34*9356374aSAndroid Build Coastguard Worker namespace absl {
35*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_BEGIN
36*9356374aSAndroid Build Coastguard Worker namespace flags_internal {
37*9356374aSAndroid Build Coastguard Worker 
38*9356374aSAndroid Build Coastguard Worker enum class UsageFlagsAction { kHandleUsage, kIgnoreUsage };
39*9356374aSAndroid Build Coastguard Worker enum class OnUndefinedFlag {
40*9356374aSAndroid Build Coastguard Worker   kIgnoreUndefined,
41*9356374aSAndroid Build Coastguard Worker   kReportUndefined,
42*9356374aSAndroid Build Coastguard Worker   kAbortIfUndefined
43*9356374aSAndroid Build Coastguard Worker };
44*9356374aSAndroid Build Coastguard Worker 
45*9356374aSAndroid Build Coastguard Worker // This is not a public interface. This interface exists to expose the ability
46*9356374aSAndroid Build Coastguard Worker // to change help output stream in case of parsing errors. This is used by
47*9356374aSAndroid Build Coastguard Worker // internal unit tests to validate expected outputs.
48*9356374aSAndroid Build Coastguard Worker // When this was written, `EXPECT_EXIT` only supported matchers on stderr,
49*9356374aSAndroid Build Coastguard Worker // but not on stdout.
50*9356374aSAndroid Build Coastguard Worker std::vector<char*> ParseCommandLineImpl(
51*9356374aSAndroid Build Coastguard Worker     int argc, char* argv[], UsageFlagsAction usage_flag_action,
52*9356374aSAndroid Build Coastguard Worker     OnUndefinedFlag undef_flag_action,
53*9356374aSAndroid Build Coastguard Worker     std::ostream& error_help_output = std::cout);
54*9356374aSAndroid Build Coastguard Worker 
55*9356374aSAndroid Build Coastguard Worker // --------------------------------------------------------------------
56*9356374aSAndroid Build Coastguard Worker // Inspect original command line
57*9356374aSAndroid Build Coastguard Worker 
58*9356374aSAndroid Build Coastguard Worker // Returns true if flag with specified name was either present on the original
59*9356374aSAndroid Build Coastguard Worker // command line or specified in flag file present on the original command line.
60*9356374aSAndroid Build Coastguard Worker bool WasPresentOnCommandLine(absl::string_view flag_name);
61*9356374aSAndroid Build Coastguard Worker 
62*9356374aSAndroid Build Coastguard Worker // Return existing flags similar to the parameter, in order to help in case of
63*9356374aSAndroid Build Coastguard Worker // misspellings.
64*9356374aSAndroid Build Coastguard Worker std::vector<std::string> GetMisspellingHints(absl::string_view flag);
65*9356374aSAndroid Build Coastguard Worker 
66*9356374aSAndroid Build Coastguard Worker }  // namespace flags_internal
67*9356374aSAndroid Build Coastguard Worker ABSL_NAMESPACE_END
68*9356374aSAndroid Build Coastguard Worker }  // namespace absl
69*9356374aSAndroid Build Coastguard Worker 
70*9356374aSAndroid Build Coastguard Worker #endif  // ABSL_FLAGS_INTERNAL_PARSE_H_
71