@@ -628,9 +628,63 @@ def subcmd_help_parser(subcmd):
628628 return
629629
630630
631+ # BZ 1581651 - Override the ArgumentParser to disable argument abbreviations.
632+ class OverrideArgumentParser (argparse .ArgumentParser ):
633+ """
634+ HACK: in order to disable abbreviation we are disabling the startswith for
635+ the options
636+ """
637+ def _get_option_tuples (self , option_string ):
638+ result = []
639+
640+ # option strings starting with two prefix characters are only
641+ # split at the '='
642+ chars = self .prefix_chars
643+ if option_string [0 ] in chars and option_string [1 ] in chars :
644+ if '=' in option_string :
645+ option_prefix , explicit_arg = option_string .split ('=' , 1 )
646+ else :
647+ option_prefix = option_string
648+ explicit_arg = None
649+ for option_string in self ._option_string_actions :
650+ # HACK original line: if option_string.startswith(option_prefix):
651+ if option_string == option_prefix :
652+ action = self ._option_string_actions [option_string ]
653+ tup = action , option_string , explicit_arg
654+ result .append (tup )
655+
656+ # single character options can be concatenated with their arguments
657+ # but multiple character options always have to have their argument
658+ # separate
659+ elif option_string [0 ] in chars and option_string [1 ] not in chars :
660+ option_prefix = option_string
661+ explicit_arg = None
662+ short_option_prefix = option_string [:2 ]
663+ short_explicit_arg = option_string [2 :]
664+
665+ for option_string in self ._option_string_actions :
666+ if option_string == short_option_prefix :
667+ action = self ._option_string_actions [option_string ]
668+ tup = action , option_string , short_explicit_arg
669+ result .append (tup )
670+ # HACK original line: elif option_string.startswith(option_prefix):
671+ elif option_string == option_prefix :
672+ action = self ._option_string_actions [option_string ]
673+ tup = action , option_string , explicit_arg
674+ result .append (tup )
675+
676+ # shouldn't ever get here
677+ else :
678+ self .error (_ ('unexpected option string: %s' ) % option_string ) ## noqa
679+
680+ # return the collected option tuples
681+ return result
682+
683+
631684def main ():
632685 """ main """
633- parser = argparse .ArgumentParser (
686+ # BZ 1581651 - Override the ArgumentParser to disable argument abbreviations.
687+ parser = OverrideArgumentParser (
634688 description = u'APB tooling for '
635689 u'assisting in building and packaging APBs.'
636690 )
0 commit comments