summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcmd2/argparse_completer.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/cmd2/argparse_completer.py b/cmd2/argparse_completer.py
index 03ff4375..0c0bc6a1 100755
--- a/cmd2/argparse_completer.py
+++ b/cmd2/argparse_completer.py
@@ -707,7 +707,7 @@ class ACHelpFormatter(argparse.RawTextHelpFormatter):
def _format_usage(self, usage, actions, groups, prefix) -> str:
if prefix is None:
- prefix = _('Usage: ')
+ prefix = _('usage: ')
# if usage is specified, use that
if usage is not None:
@@ -738,7 +738,7 @@ class ACHelpFormatter(argparse.RawTextHelpFormatter):
# build full usage string
format = self._format_actions_usage
- action_usage = format(positionals + required_options + optionals, groups)
+ action_usage = format(required_options + optionals + positionals, groups)
usage = ' '.join([s for s in [prog, action_usage] if s])
# wrap the usage parts if it's too long
@@ -749,15 +749,15 @@ class ACHelpFormatter(argparse.RawTextHelpFormatter):
# break usage into wrappable parts
part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
+ req_usage = format(required_options, groups)
opt_usage = format(optionals, groups)
pos_usage = format(positionals, groups)
- req_usage = format(required_options, groups)
+ req_parts = _re.findall(part_regexp, req_usage)
opt_parts = _re.findall(part_regexp, opt_usage)
pos_parts = _re.findall(part_regexp, pos_usage)
- req_parts = _re.findall(part_regexp, req_usage)
+ assert ' '.join(req_parts) == req_usage
assert ' '.join(opt_parts) == opt_usage
assert ' '.join(pos_parts) == pos_usage
- assert ' '.join(req_parts) == req_usage
# End cmd2 customization
@@ -787,13 +787,15 @@ class ACHelpFormatter(argparse.RawTextHelpFormatter):
if len(prefix) + len(prog) <= 0.75 * text_width:
indent = ' ' * (len(prefix) + len(prog) + 1)
# Begin cmd2 customization
- if opt_parts:
- lines = get_lines([prog] + pos_parts, indent, prefix)
- lines.extend(get_lines(req_parts, indent))
+ if req_parts:
+ lines = get_lines([prog] + req_parts, indent, prefix)
lines.extend(get_lines(opt_parts, indent))
+ lines.extend(get_lines(pos_parts, indent))
+ elif opt_parts:
+ lines = get_lines([prog] + opt_parts, indent, prefix)
+ lines.extend(get_lines(pos_parts, indent))
elif pos_parts:
lines = get_lines([prog] + pos_parts, indent, prefix)
- lines.extend(get_lines(req_parts, indent))
else:
lines = [prog]
# End cmd2 customization
@@ -806,9 +808,9 @@ class ACHelpFormatter(argparse.RawTextHelpFormatter):
lines = get_lines(parts, indent)
if len(lines) > 1:
lines = []
- lines.extend(get_lines(pos_parts, indent))
lines.extend(get_lines(req_parts, indent))
lines.extend(get_lines(opt_parts, indent))
+ lines.extend(get_lines(pos_parts, indent))
# End cmd2 customization
lines = [prog] + lines