| 38 | } |
| 39 | |
| 40 | ParsedCommand CommandParser::Parse() { |
| 41 | ParseGlobalOptions(); |
| 42 | |
| 43 | ParsedCommand cmd; |
| 44 | cmd.verbose = verbose_; |
| 45 | |
| 46 | if (argc_ < 2) { |
| 47 | return cmd; |
| 48 | } |
| 49 | |
| 50 | cmd.command = argv_[1]; |
| 51 | |
| 52 | if (!spec_) { |
| 53 | // No spec, just collect all args as positional |
| 54 | for (int i = 2; i < argc_; i++) { |
| 55 | std::string arg = argv_[i]; |
| 56 | if (!IsShortOption(arg) && !IsLongOption(arg)) { |
| 57 | cmd.arguments.push_back(arg); |
| 58 | } |
| 59 | } |
| 60 | return cmd; |
| 61 | } |
| 62 | |
| 63 | ParseCommandOptions(cmd); |
| 64 | |
| 65 | if (spec_) { |
| 66 | ValidateParsedCommand(cmd); |
| 67 | } |
| 68 | |
| 69 | return cmd; |
| 70 | } |
| 71 | |
| 72 | void CommandParser::ParseCommandOptions(ParsedCommand& cmd) { |
| 73 | for (int i = 2; i < argc_; i++) { |