Android-cuttlefish cvd tool
gflags_compat.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <optional>
20#include <ostream>
21#include <string>
22#include <vector>
23
25
26namespace cuttlefish {
27
28/* Write gflags `--helpxml` style output for a string-type flag. */
29void WriteGflagsCompatXml(const Flag&, std::ostream&);
30void WriteGflagsCompatXml(const std::vector<Flag>&, std::ostream&);
31
32// Create a flag resembling a gflags argument of the given type. This includes
33// "-[-]flag=*",support for all types, "-[-]noflag" support for booleans, and
34// "-flag *", "--flag *", support for other types. The value passed in the flag
35// is saved to the defined reference.
36Flag GflagsCompatFlag(const std::string& name, std::string& value);
37Flag GflagsCompatFlag(const std::string& name, int32_t& value);
38Flag GflagsCompatFlag(const std::string& name, size_t& value);
39Flag GflagsCompatFlag(const std::string& name, bool& value);
40Flag GflagsCompatFlag(const std::string& name, std::vector<std::string>& value);
41Flag GflagsCompatFlag(const std::string& name, std::vector<unsigned>& value);
42Flag GflagsCompatFlag(const std::string& name, std::vector<bool>& value,
43 bool default_value);
44// Indicates when to assign std::nullopt to the std::optional backing the flag.
45enum class CoerceToNullopt {
46 None, // When the flag is not present in the arguments
47 UnsetKeyword, // When the flag has the "unset" special value.
48 EmptyString, // When the flag has an empty value (`--flag "" or `--flag=`)
49};
50Flag GflagsCompatFlag(const std::string& name,
51 std::optional<std::string>& value,
53Flag GflagsCompatFlag(const std::string& name, std::optional<int>& value,
55Flag GflagsCompatFlag(const std::string& name, std::optional<size_t>& value,
57Flag GflagsCompatFlag(const std::string& name, std::optional<unsigned>& value,
59Flag GflagsCompatFlag(const std::string& name, std::optional<int64_t>& value,
61Flag GflagsCompatFlag(const std::string& name, std::optional<bool>& value,
63
64Flag GflagsCompatFlag(const std::string& name,
65 std::optional<std::vector<std::string>>& value,
67Flag GflagsCompatFlag(const std::string& name,
68 std::optional<std::vector<unsigned>>& value,
70
71/* If a "-help" or "--help" flag is present, prints all the flags and fails. */
72Flag HelpFlag(const std::vector<Flag>& flags, std::string text = "");
73
74/* If a "-helpxml" is present, prints all the flags in XML and fails. */
75Flag HelpXmlFlag(const std::vector<Flag>& flags, std::ostream&, bool& print_xml,
76 std::string text = "");
77
78} // namespace cuttlefish
static const char *const text[]
Definition: ext2_err.c:10
char * name
Definition: libf2fs.c:1403
Definition: alloc_driver.h:20
Flag GflagsCompatFlag(const std::string &name, std::string &value)
Definition: gflags_compat.cpp:280
void WriteGflagsCompatXml(const Flag &flag, std::ostream &out)
Definition: gflags_compat.cpp:214
Flag HelpFlag(const std::vector< Flag > &flags, std::string text)
Definition: gflags_compat.cpp:242
Flag HelpXmlFlag(const std::vector< Flag > &flags, std::ostream &out, bool &print_xml, std::string text)
Definition: gflags_compat.cpp:257
CoerceToNullopt
Definition: gflags_compat.h:45
Flag
Definition: udp.h:67