@@ -750,7 +750,7 @@ def _format_usage(self, usage, actions, groups, prefix) -> str:
750750
751751 # build full usage string
752752 format = self ._format_actions_usage
753- action_usage = format (positionals + required_options + optionals , groups )
753+ action_usage = format (required_options + optionals + positionals , groups )
754754 usage = ' ' .join ([s for s in [prog , action_usage ] if s ])
755755
756756 # wrap the usage parts if it's too long
@@ -761,15 +761,15 @@ def _format_usage(self, usage, actions, groups, prefix) -> str:
761761
762762 # break usage into wrappable parts
763763 part_regexp = r'\(.*?\)+|\[.*?\]+|\S+'
764+ req_usage = format (required_options , groups )
764765 opt_usage = format (optionals , groups )
765766 pos_usage = format (positionals , groups )
766- req_usage = format ( required_options , groups )
767+ req_parts = _re . findall ( part_regexp , req_usage )
767768 opt_parts = _re .findall (part_regexp , opt_usage )
768769 pos_parts = _re .findall (part_regexp , pos_usage )
769- req_parts = _re . findall ( part_regexp , req_usage )
770+ assert ' ' . join ( req_parts ) == req_usage
770771 assert ' ' .join (opt_parts ) == opt_usage
771772 assert ' ' .join (pos_parts ) == pos_usage
772- assert ' ' .join (req_parts ) == req_usage
773773
774774 # End cmd2 customization
775775
@@ -799,13 +799,15 @@ def get_lines(parts, indent, prefix=None):
799799 if len (prefix ) + len (prog ) <= 0.75 * text_width :
800800 indent = ' ' * (len (prefix ) + len (prog ) + 1 )
801801 # Begin cmd2 customization
802- if opt_parts :
803- lines = get_lines ([prog ] + pos_parts , indent , prefix )
804- lines .extend (get_lines (req_parts , indent ))
802+ if req_parts :
803+ lines = get_lines ([prog ] + req_parts , indent , prefix )
805804 lines .extend (get_lines (opt_parts , indent ))
805+ lines .extend (get_lines (pos_parts , indent ))
806+ elif opt_parts :
807+ lines = get_lines ([prog ] + opt_parts , indent , prefix )
808+ lines .extend (get_lines (pos_parts , indent ))
806809 elif pos_parts :
807810 lines = get_lines ([prog ] + pos_parts , indent , prefix )
808- lines .extend (get_lines (req_parts , indent ))
809811 else :
810812 lines = [prog ]
811813 # End cmd2 customization
@@ -814,13 +816,13 @@ def get_lines(parts, indent, prefix=None):
814816 else :
815817 indent = ' ' * len (prefix )
816818 # Begin cmd2 customization
817- parts = pos_parts + req_parts + opt_parts
819+ parts = req_parts + opt_parts + pos_parts
818820 lines = get_lines (parts , indent )
819821 if len (lines ) > 1 :
820822 lines = []
821- lines .extend (get_lines (pos_parts , indent ))
822823 lines .extend (get_lines (req_parts , indent ))
823824 lines .extend (get_lines (opt_parts , indent ))
825+ lines .extend (get_lines (pos_parts , indent ))
824826 # End cmd2 customization
825827 lines = [prog ] + lines
826828
@@ -889,6 +891,9 @@ def _format_args(self, action, default_metavar) -> str:
889891 result = super ()._format_args (action , default_metavar )
890892 return result
891893
894+ def format_help (self ):
895+ return super ().format_help () + '\n '
896+
892897
893898# noinspection PyCompatibility
894899class ACArgumentParser (argparse .ArgumentParser ):
0 commit comments