diff options
| author | thegeorg <[email protected]> | 2025-09-04 00:36:43 +0300 |
|---|---|---|
| committer | thegeorg <[email protected]> | 2025-09-04 00:56:46 +0300 |
| commit | 76db84e05fa0cd826fae55327cfaa6eaab3981d1 (patch) | |
| tree | cd24252df3d90763e1cd0d5466ce81410ae734b8 /library/cpp | |
| parent | 6e1d6d9b8c79129bbb490819d57a1ef5d896c586 (diff) | |
Make reset modes mutually exclusive
* Support variadic configuration of MutuallyExclusive
* Use it to forbid passing conflicting modes to `arc reset`
commit_hash:cf056645a91fde017d33cbfffe461229c9c3fc39
Diffstat (limited to 'library/cpp')
| -rw-r--r-- | library/cpp/getopt/last_getopt_demo/demo.cpp | 4 | ||||
| -rw-r--r-- | library/cpp/getopt/small/last_getopt_opts.h | 19 |
2 files changed, 18 insertions, 5 deletions
diff --git a/library/cpp/getopt/last_getopt_demo/demo.cpp b/library/cpp/getopt/last_getopt_demo/demo.cpp index a0e82a936cd..3e98db97d4f 100644 --- a/library/cpp/getopt/last_getopt_demo/demo.cpp +++ b/library/cpp/getopt/last_getopt_demo/demo.cpp @@ -121,8 +121,8 @@ protected: }) .Completer(NLastGetopt::NComp::File()); - // These two options can't be together. - opts.MutuallyExclusive("post-file", "post-data"); + // These options can not appear together. + opts.MutuallyExclusive("method", "post-file", "post-data"); opts.AddLongOption("header") .RequiredArgument("header-line") diff --git a/library/cpp/getopt/small/last_getopt_opts.h b/library/cpp/getopt/small/last_getopt_opts.h index 718dbfcb893..cb1e0227633 100644 --- a/library/cpp/getopt/small/last_getopt_opts.h +++ b/library/cpp/getopt/small/last_getopt_opts.h @@ -398,9 +398,22 @@ namespace NLastGetopt { * Note: don't use this on options with default values. If option with default value wasn't specified, * parser will run handlers for default value, thus triggering a false-positive exclusivity check. */ - template <typename T1, typename T2> - void MutuallyExclusive(T1&& opt1, T2&& opt2) { - MutuallyExclusiveOpt(GetOption(std::forward<T1>(opt1)), GetOption(std::forward<T2>(opt2))); + template <typename Opt1, typename Opt2> + void MutuallyExclusive(Opt1&& name1, Opt2&& name2) { + TOpt& opt1 = GetOption(name1); + TOpt& opt2 = GetOption(name2); + MutuallyExclusiveOpt(opt1, opt2); + } + + template <typename Opt1, typename... OtherOpts> + void MutuallyExclusive(Opt1&& name1, OtherOpts&& ...otherNames) { + TOpt& opt1 = GetOption(name1); + std::array<std::string_view, sizeof...(OtherOpts)> otherNamesArr{otherNames...}; + for (const auto& otherName: otherNamesArr) { + TOpt& otherOpt = GetOption(otherName); + MutuallyExclusiveOpt(opt1, otherOpt); + } + MutuallyExclusive(std::forward<OtherOpts>(otherNames)...); } /** |
