| 627 | |
| 628 | template <typename Range> |
| 629 | bool QueryWindowsRegistry(Range args, cmExecutionStatus& status, |
| 630 | std::string const& variable) |
| 631 | { |
| 632 | using View = cmWindowsRegistry::View; |
| 633 | if (args.empty()) { |
| 634 | status.SetError("missing <key> specification."); |
| 635 | return false; |
| 636 | } |
| 637 | std::string const& key = *args.begin(); |
| 638 | |
| 639 | struct Arguments : public ArgumentParser::ParseResult |
| 640 | { |
| 641 | std::string ValueName; |
| 642 | bool ValueNames = false; |
| 643 | bool SubKeys = false; |
| 644 | std::string View; |
| 645 | std::string Separator; |
| 646 | std::string ErrorVariable; |
| 647 | }; |
| 648 | cmArgumentParser<Arguments> parser; |
| 649 | parser.Bind("VALUE"_s, &Arguments::ValueName) |
| 650 | .Bind("VALUE_NAMES"_s, &Arguments::ValueNames) |
| 651 | .Bind("SUBKEYS"_s, &Arguments::SubKeys) |
| 652 | .Bind("VIEW"_s, &Arguments::View) |
| 653 | .Bind("SEPARATOR"_s, &Arguments::Separator) |
| 654 | .Bind("ERROR_VARIABLE"_s, &Arguments::ErrorVariable); |
| 655 | std::vector<std::string> invalidArgs; |
| 656 | |
| 657 | Arguments const arguments = parser.Parse(args.advance(1), &invalidArgs); |
| 658 | if (!invalidArgs.empty()) { |
| 659 | status.SetError(cmStrCat("given invalid argument(s) \"", |
| 660 | cmJoin(invalidArgs, ", "_s), "\".")); |
| 661 | return false; |
| 662 | } |
| 663 | if (arguments.MaybeReportError(status.GetMakefile())) { |
| 664 | return true; |
| 665 | } |
| 666 | if ((!arguments.ValueName.empty() && |
| 667 | (arguments.ValueNames || arguments.SubKeys)) || |
| 668 | (arguments.ValueName.empty() && arguments.ValueNames && |
| 669 | arguments.SubKeys)) { |
| 670 | status.SetError("given mutually exclusive sub-options VALUE, " |
| 671 | "VALUE_NAMES or SUBKEYS."); |
| 672 | return false; |
| 673 | } |
| 674 | |
| 675 | if (!arguments.View.empty() && !cmWindowsRegistry::ToView(arguments.View)) { |
| 676 | status.SetError( |
| 677 | cmStrCat("given invalid value for VIEW: ", arguments.View, '.')); |
| 678 | return false; |
| 679 | } |
| 680 | |
| 681 | auto& makefile = status.GetMakefile(); |
| 682 | |
| 683 | makefile.AddDefinition(variable, ""_s); |
| 684 | |
| 685 | auto view = arguments.View.empty() |
| 686 | ? View::Both |
no test coverage detected
searching dependent graphs…