| 2786 | } |
| 2787 | |
| 2788 | bool HandleGenerateCommand(std::vector<std::string> const& args, |
| 2789 | cmExecutionStatus& status) |
| 2790 | { |
| 2791 | if (args.size() < 5) { |
| 2792 | status.SetError("Incorrect arguments to GENERATE subcommand."); |
| 2793 | return false; |
| 2794 | } |
| 2795 | |
| 2796 | struct Arguments : public ArgumentParser::ParseResult |
| 2797 | { |
| 2798 | cm::optional<std::string> Output; |
| 2799 | cm::optional<std::string> Input; |
| 2800 | cm::optional<std::string> Content; |
| 2801 | cm::optional<std::string> Condition; |
| 2802 | cm::optional<std::string> Target; |
| 2803 | cm::optional<std::string> NewLineStyle; |
| 2804 | bool NoSourcePermissions = false; |
| 2805 | bool UseSourcePermissions = false; |
| 2806 | ArgumentParser::NonEmpty<std::vector<std::string>> FilePermissions; |
| 2807 | std::vector<cm::string_view> ParsedKeywords; |
| 2808 | }; |
| 2809 | |
| 2810 | static auto const parser = |
| 2811 | cmArgumentParser<Arguments>{} |
| 2812 | .Bind("OUTPUT"_s, &Arguments::Output) |
| 2813 | .Bind("INPUT"_s, &Arguments::Input) |
| 2814 | .Bind("CONTENT"_s, &Arguments::Content) |
| 2815 | .Bind("CONDITION"_s, &Arguments::Condition) |
| 2816 | .Bind("TARGET"_s, &Arguments::Target) |
| 2817 | .Bind("NO_SOURCE_PERMISSIONS"_s, &Arguments::NoSourcePermissions) |
| 2818 | .Bind("USE_SOURCE_PERMISSIONS"_s, &Arguments::UseSourcePermissions) |
| 2819 | .Bind("FILE_PERMISSIONS"_s, &Arguments::FilePermissions) |
| 2820 | .Bind("NEWLINE_STYLE"_s, &Arguments::NewLineStyle) |
| 2821 | .BindParsedKeywords(&Arguments::ParsedKeywords); |
| 2822 | |
| 2823 | std::vector<std::string> unparsedArguments; |
| 2824 | Arguments const arguments = |
| 2825 | parser.Parse(cmMakeRange(args).advance(1), &unparsedArguments); |
| 2826 | |
| 2827 | if (arguments.MaybeReportError(status.GetMakefile())) { |
| 2828 | return true; |
| 2829 | } |
| 2830 | |
| 2831 | if (!unparsedArguments.empty()) { |
| 2832 | status.SetError("Unknown argument to GENERATE subcommand."); |
| 2833 | return false; |
| 2834 | } |
| 2835 | |
| 2836 | if (!arguments.Output || arguments.ParsedKeywords[0] != "OUTPUT"_s) { |
| 2837 | status.SetError("GENERATE requires OUTPUT as first option."); |
| 2838 | return false; |
| 2839 | } |
| 2840 | std::string const& output = *arguments.Output; |
| 2841 | |
| 2842 | if (!arguments.Input && !arguments.Content) { |
| 2843 | status.SetError("GENERATE requires INPUT or CONTENT option."); |
| 2844 | return false; |
| 2845 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…