| 175 | } |
| 176 | |
| 177 | bool ArgsManager::ParseParameters(int argc, const char* const argv[], std::string& error) |
| 178 | { |
| 179 | LOCK(cs_args); |
| 180 | m_settings.command_line_options.clear(); |
| 181 | |
| 182 | for (int i = 1; i < argc; i++) { |
| 183 | std::string key(argv[i]); |
| 184 | |
| 185 | #ifdef __APPLE__ |
| 186 | // At the first time when a user gets the "App downloaded from the |
| 187 | // internet" warning, and clicks the Open button, macOS passes |
| 188 | // a unique process serial number (PSN) as -psn_... command-line |
| 189 | // argument, which we filter out. |
| 190 | if (key.starts_with("-psn_")) continue; |
| 191 | #endif |
| 192 | |
| 193 | if (key == "-") break; //bitcoin-tx using stdin |
| 194 | std::optional<std::string> val; |
| 195 | size_t is_index = key.find('='); |
| 196 | if (is_index != std::string::npos) { |
| 197 | val = key.substr(is_index + 1); |
| 198 | key.erase(is_index); |
| 199 | } |
| 200 | #ifdef WIN32 |
| 201 | key = ToLower(key); |
| 202 | if (key[0] == '/') |
| 203 | key[0] = '-'; |
| 204 | #endif |
| 205 | |
| 206 | if (key[0] != '-') { |
| 207 | if (!m_accept_any_command && m_command.empty()) { |
| 208 | // The first non-dash arg is a registered command |
| 209 | std::optional<unsigned int> flags = GetArgFlags_(key); |
| 210 | if (!flags || !(*flags & ArgsManager::COMMAND)) { |
| 211 | error = strprintf("Invalid command '%s'", argv[i]); |
| 212 | return false; |
| 213 | } |
| 214 | } |
| 215 | m_command.push_back(key); |
| 216 | while (++i < argc) { |
| 217 | // The remaining args are command args |
| 218 | m_command.emplace_back(argv[i]); |
| 219 | } |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | // Transform --foo to -foo |
| 224 | if (key.length() > 1 && key[1] == '-') |
| 225 | key.erase(0, 1); |
| 226 | |
| 227 | // Transform -foo to foo |
| 228 | key.erase(0, 1); |
| 229 | KeyInfo keyinfo = InterpretKey(key); |
| 230 | std::optional<unsigned int> flags = GetArgFlags_('-' + keyinfo.name); |
| 231 | |
| 232 | // Unknown command line options and command line options with dot |
| 233 | // characters (which are returned from InterpretKey with nonempty |
| 234 | // section strings) are not valid. |