tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

usage.h (3683B)


      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 <ostream>
     21 #include <string>
     22 
     23 #include "absl/base/config.h"
     24 #include "absl/flags/commandlineflag.h"
     25 #include "absl/strings/string_view.h"
     26 
     27 // --------------------------------------------------------------------
     28 // Usage reporting interfaces
     29 
     30 namespace absl {
     31 ABSL_NAMESPACE_BEGIN
     32 namespace flags_internal {
     33 
     34 // The format to report the help messages in.
     35 enum class HelpFormat {
     36  kHumanReadable,
     37 };
     38 
     39 // The kind of usage help requested.
     40 enum class HelpMode {
     41  kNone,
     42  kImportant,
     43  kShort,
     44  kFull,
     45  kPackage,
     46  kMatch,
     47  kVersion,
     48  kOnlyCheckArgs
     49 };
     50 
     51 // Streams the help message describing `flag` to `out`.
     52 // The default value for `flag` is included in the output.
     53 void FlagHelp(std::ostream& out, const CommandLineFlag& flag,
     54              HelpFormat format = HelpFormat::kHumanReadable);
     55 
     56 // Produces the help messages for all flags matching the filter. A flag matches
     57 // the filter if it is defined in a file with a filename which includes
     58 // filter string as a substring. You can use '/' and '.' to restrict the
     59 // matching to a specific file names. For example:
     60 //   FlagsHelp(out, "/path/to/file.");
     61 // restricts help to only flags which resides in files named like:
     62 //  .../path/to/file.<ext>
     63 // for any extension 'ext'. If the filter is empty this function produces help
     64 // messages for all flags.
     65 void FlagsHelp(std::ostream& out, absl::string_view filter,
     66               HelpFormat format, absl::string_view program_usage_message);
     67 
     68 // --------------------------------------------------------------------
     69 
     70 // If any of the 'usage' related command line flags (listed on the bottom of
     71 // this file) has been set this routine produces corresponding help message in
     72 // the specified output stream and returns HelpMode that was handled. Otherwise
     73 // it returns HelpMode::kNone.
     74 HelpMode HandleUsageFlags(std::ostream& out,
     75                          absl::string_view program_usage_message);
     76 
     77 // --------------------------------------------------------------------
     78 // Encapsulates the logic of exiting the binary depending on handled help mode.
     79 
     80 void MaybeExit(HelpMode mode);
     81 
     82 // --------------------------------------------------------------------
     83 // Globals representing usage reporting flags
     84 
     85 // Returns substring to filter help output (--help=substr argument)
     86 std::string GetFlagsHelpMatchSubstr();
     87 // Returns the requested help mode.
     88 HelpMode GetFlagsHelpMode();
     89 // Returns the requested help format.
     90 HelpFormat GetFlagsHelpFormat();
     91 
     92 // These are corresponding setters to the attributes above.
     93 void SetFlagsHelpMatchSubstr(absl::string_view);
     94 void SetFlagsHelpMode(HelpMode);
     95 void SetFlagsHelpFormat(HelpFormat);
     96 
     97 // Deduces usage flags from the input argument in a form --name=value or
     98 // --name. argument is already split into name and value before we call this
     99 // function.
    100 bool DeduceUsageFlags(absl::string_view name, absl::string_view value);
    101 
    102 }  // namespace flags_internal
    103 ABSL_NAMESPACE_END
    104 }  // namespace absl
    105 
    106 #endif  // ABSL_FLAGS_INTERNAL_USAGE_H_