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