1//
2// Copyright 2019 The Abseil Authors.
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// https://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#ifndef ABSL_FLAGS_INTERNAL_USAGE_H_
17#define ABSL_FLAGS_INTERNAL_USAGE_H_
18
19#include <iosfwd>
20#include <string>
21
22#include "absl/flags/declare.h"
23#include "absl/flags/internal/commandlineflag.h"
24#include "absl/strings/string_view.h"
25
26// --------------------------------------------------------------------
27// Usage reporting interfaces
28
29namespace absl {
30namespace flags_internal {
31
32// Sets the "usage" message to be used by help reporting routines.
33// For example:
34// absl::SetProgramUsageMessage(
35// absl::StrCat("This program does nothing. Sample usage:\n", argv[0],
36// " <uselessarg1> <uselessarg2>"));
37// Do not include commandline flags in the usage: we do that for you!
38// Note: Calling SetProgramUsageMessage twice will trigger a call to std::exit.
39void SetProgramUsageMessage(absl::string_view new_usage_message);
40
41// Returns the usage message set by SetProgramUsageMessage().
42absl::string_view ProgramUsageMessage();
43
44// --------------------------------------------------------------------
45
46// The format to report the help messages in.
47enum class HelpFormat {
48 kHumanReadable,
49};
50
51// Outputs the help message describing specific flag.
52void FlagHelp(std::ostream& out, const flags_internal::CommandLineFlag& flag,
53 HelpFormat format = HelpFormat::kHumanReadable);
54
55// Produces the help messages for all flags matching the filter. A flag matches
56// the filter if it is defined in a file with a filename which includes
57// filter string as a substring. You can use '/' and '.' to restrict the
58// matching to a specific file names. For example:
59// FlagsHelp(out, "/path/to/file.");
60// restricts help to only flags which resides in files named like:
61// .../path/to/file.<ext>
62// for any extension 'ext'. If the filter is empty this function produces help
63// messages for all flags.
64void FlagsHelp(std::ostream& out, absl::string_view filter = {},
65 HelpFormat format = HelpFormat::kHumanReadable);
66
67// --------------------------------------------------------------------
68
69// If any of the 'usage' related command line flags (listed on the bottom of
70// this file) has been set this routine produces corresponding help message in
71// the specified output stream and returns:
72// 0 - if "version" or "only_check_flags" flags were set and handled.
73// 1 - if some other 'usage' related flag was set and handled.
74// -1 - if no usage flags were set on a commmand line.
75// Non negative return values are expected to be used as an exit code for a
76// binary.
77int HandleUsageFlags(std::ostream& out);
78
79} // namespace flags_internal
80} // namespace absl
81
82ABSL_DECLARE_FLAG(bool, help);
83ABSL_DECLARE_FLAG(bool, helpfull);
84ABSL_DECLARE_FLAG(bool, helpshort);
85ABSL_DECLARE_FLAG(bool, helppackage);
86ABSL_DECLARE_FLAG(bool, version);
87ABSL_DECLARE_FLAG(bool, only_check_args);
88ABSL_DECLARE_FLAG(std::string, helpon);
89ABSL_DECLARE_FLAG(std::string, helpmatch);
90
91#endif // ABSL_FLAGS_INTERNAL_USAGE_H_
92