|
6 | 6 |
|
7 | 7 | #pragma once
|
8 | 8 |
|
| 9 | +// IWYU pragma: private, include "CLI/CLI.hpp" |
| 10 | + |
9 | 11 | // [CLI11:public_includes:set]
|
10 | 12 | #include <algorithm>
|
11 | 13 | #include <cstdint>
|
@@ -733,6 +735,10 @@ class App {
|
733 | 735 | /// Check to see if a subcommand is part of this command (text version)
|
734 | 736 | CLI11_NODISCARD App *get_subcommand(std::string subcom) const;
|
735 | 737 |
|
| 738 | + /// Get a subcommand by name (noexcept non-const version) |
| 739 | + /// returns null if subcommand doesn't exist |
| 740 | + CLI11_NODISCARD App *get_subcommand_no_throw(std::string subcom) const noexcept; |
| 741 | + |
736 | 742 | /// Get a pointer to subcommand by index
|
737 | 743 | CLI11_NODISCARD App *get_subcommand(int index = 0) const;
|
738 | 744 |
|
@@ -907,8 +913,9 @@ class App {
|
907 | 913 | }
|
908 | 914 |
|
909 | 915 | /// Check with name instead of pointer to see if subcommand was selected
|
910 |
| - CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const { |
911 |
| - return get_subcommand(subcommand_name)->parsed_ > 0; |
| 916 | + CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const noexcept { |
| 917 | + App *sub = get_subcommand_no_throw(subcommand_name); |
| 918 | + return (sub != nullptr) ? (sub->parsed_ > 0) : false; |
912 | 919 | }
|
913 | 920 |
|
914 | 921 | /// Sets excluded options for the subcommand
|
@@ -1038,7 +1045,7 @@ class App {
|
1038 | 1045 | std::vector<Option *> get_options(const std::function<bool(Option *)> filter = {});
|
1039 | 1046 |
|
1040 | 1047 | /// Get an option by name (noexcept non-const version)
|
1041 |
| - Option *get_option_no_throw(std::string option_name) noexcept; |
| 1048 | + CLI11_NODISCARD Option *get_option_no_throw(std::string option_name) noexcept; |
1042 | 1049 |
|
1043 | 1050 | /// Get an option by name (noexcept const version)
|
1044 | 1051 | CLI11_NODISCARD const Option *get_option_no_throw(std::string option_name) const noexcept;
|
@@ -1437,5 +1444,5 @@ struct AppFriend {
|
1437 | 1444 | } // namespace CLI
|
1438 | 1445 |
|
1439 | 1446 | #ifndef CLI11_COMPILE
|
1440 |
| -#include "impl/App_inl.hpp" |
| 1447 | +#include "impl/App_inl.hpp" // IWYU pragma: export |
1441 | 1448 | #endif
|
0 commit comments