| 96 | |
| 97 | |
| 98 | int Commands::ShellCompletion::RunCommand(const std::string &arg0, |
| 99 | unsigned int ignored_skip, |
| 100 | int argc, |
| 101 | char **argv) |
| 102 | { |
| 103 | try |
| 104 | { |
| 105 | ParsedArgs::Ptr args = parse_commandline(arg0, 1, argc, argv); |
| 106 | |
| 107 | if (!args->GetCompleted()) |
| 108 | { |
| 109 | return 0; |
| 110 | } |
| 111 | |
| 112 | if (args->Present("list-commands") |
| 113 | && args->Present("list-options")) |
| 114 | { |
| 115 | throw CommandException("shell-completion", |
| 116 | "Cannot combine --list-commands and --list-options"); |
| 117 | } |
| 118 | |
| 119 | if (args->Present("list-options") && args->GetValueLen("list-options") > 1) |
| 120 | { |
| 121 | throw CommandException("shell-completion", |
| 122 | "Can only use --list-options once"); |
| 123 | } |
| 124 | |
| 125 | if (args->Present("arg-helper") |
| 126 | && !args->Present("list-options")) |
| 127 | { |
| 128 | throw CommandException("shell-completion", |
| 129 | "--arg-helper requires --list-options"); |
| 130 | } |
| 131 | |
| 132 | if (args->Present("list-commands")) |
| 133 | { |
| 134 | list_commands(); |
| 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | if (args->Present("list-options")) |
| 139 | { |
| 140 | if (!args->Present("arg-helper")) |
| 141 | { |
| 142 | list_options(args->GetValue("list-options", 0)); |
| 143 | } |
| 144 | else |
| 145 | { |
| 146 | call_arg_helper(args->GetValue("list-options", 0), |
| 147 | args->GetValue("arg-helper", 0)); |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | catch (...) |
| 152 | { |
| 153 | throw; |
| 154 | } |
| 155 | return 3; |