| 96 | } |
| 97 | |
| 98 | static bool parse_options(int argc, char ** argv, analysis_options & opts) { |
| 99 | if (argc < 2) { |
| 100 | print_usage(argv[0]); |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | for (int i = 1; i < argc; ++i) { |
| 105 | std::string arg = argv[i]; |
| 106 | |
| 107 | if (arg == "--all") { |
| 108 | opts.analyze_all = true; |
| 109 | } else if (arg == "--template") { |
| 110 | if (i + 1 >= argc) { |
| 111 | LOG_ERR("--template requires an argument\n"); |
| 112 | return false; |
| 113 | } |
| 114 | std::string pattern = argv[++i]; |
| 115 | std::transform(pattern.begin(), pattern.end(), pattern.begin(), ::tolower); |
| 116 | |
| 117 | // Find matching templates |
| 118 | bool found = false; |
| 119 | for (const auto & path : ALL_TEMPLATE_PATHS) { |
| 120 | std::string path_lower = path; |
| 121 | std::transform(path_lower.begin(), path_lower.end(), path_lower.begin(), ::tolower); |
| 122 | if (path_lower.find(pattern) != std::string::npos) { |
| 123 | opts.template_paths.push_back(path); |
| 124 | found = true; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | if (!found) { |
| 129 | LOG_ERR("No templates found matching: %s\n", pattern.c_str()); |
| 130 | return false; |
| 131 | } |
| 132 | } else if (arg == "--template-file") { |
| 133 | if (i + 1 >= argc) { |
| 134 | LOG_ERR("--template-file requires an argument\n"); |
| 135 | return false; |
| 136 | } |
| 137 | opts.template_paths.push_back(argv[++i]); |
| 138 | } else { |
| 139 | LOG_ERR("Unknown option: %s\n", arg.c_str()); |
| 140 | print_usage(argv[0]); |
| 141 | return false; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | if (opts.analyze_all) { |
| 146 | opts.template_paths = ALL_TEMPLATE_PATHS; |
| 147 | } |
| 148 | |
| 149 | if (opts.template_paths.empty()) { |
| 150 | LOG_ERR("No templates specified\n"); |
| 151 | print_usage(argv[0]); |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | return true; |