(self, actions, groups)
| 409 | return '%s%s\n\n' % (prefix, usage) |
| 410 | |
| 411 | def _format_actions_usage(self, actions, groups): |
| 412 | # find group indices and identify actions in groups |
| 413 | group_actions = set() |
| 414 | inserts = {} |
| 415 | for group in groups: |
| 416 | try: |
| 417 | start = actions.index(group._group_actions[0]) |
| 418 | except ValueError: |
| 419 | continue |
| 420 | else: |
| 421 | end = start + len(group._group_actions) |
| 422 | if actions[start:end] == group._group_actions: |
| 423 | for action in group._group_actions: |
| 424 | group_actions.add(action) |
| 425 | if not group.required: |
| 426 | if start in inserts: |
| 427 | inserts[start] += ' [' |
| 428 | else: |
| 429 | inserts[start] = '[' |
| 430 | inserts[end] = ']' |
| 431 | else: |
| 432 | if start in inserts: |
| 433 | inserts[start] += ' (' |
| 434 | else: |
| 435 | inserts[start] = '(' |
| 436 | inserts[end] = ')' |
| 437 | for i in range(start + 1, end): |
| 438 | inserts[i] = '|' |
| 439 | |
| 440 | # collect all actions format strings |
| 441 | parts = [] |
| 442 | for i, action in enumerate(actions): |
| 443 | |
| 444 | # suppressed arguments are marked with None |
| 445 | # remove | separators for suppressed arguments |
| 446 | if action.help is SUPPRESS: |
| 447 | parts.append(None) |
| 448 | if inserts.get(i) == '|': |
| 449 | inserts.pop(i) |
| 450 | elif inserts.get(i + 1) == '|': |
| 451 | inserts.pop(i + 1) |
| 452 | |
| 453 | # produce all arg strings |
| 454 | elif not action.option_strings: |
| 455 | part = self._format_args(action, action.dest) |
| 456 | |
| 457 | # if it's in a group, strip the outer [] |
| 458 | if action in group_actions: |
| 459 | if part[0] == '[' and part[-1] == ']': |
| 460 | part = part[1:-1] |
| 461 | |
| 462 | # add the action string to the list |
| 463 | parts.append(part) |
| 464 | |
| 465 | # produce the first way to invoke the option in brackets |
| 466 | else: |
| 467 | option_string = action.option_strings[0] |
| 468 |
nothing calls this directly
no test coverage detected