diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2013-03-08 11:48:23 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2013-03-22 21:03:31 +0100 |
commit | 3d80b2f671db3e4420bf308b290eddd634d1d437 (patch) | |
tree | 259626dd443bbee1430a9b469086634e953c783e /gbp/git/repository.py | |
parent | dcf746752a942e6300b1534c8119c2da84b26d8f (diff) |
GitRepository/_cmd_has_feature: more intelligent parsing
More intelligent parsing of the git output (man page). Try to
parse optional options like '--[no-]standard-notes' of git-show
correctly. In this example both 'no-standard-notes' and 'standard-notes'
would be available.
Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com>
Diffstat (limited to 'gbp/git/repository.py')
-rw-r--r-- | gbp/git/repository.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py index 4820e3f..9dd4748 100644 --- a/gbp/git/repository.py +++ b/gbp/git/repository.py @@ -183,12 +183,19 @@ class GitRepository(object): # Parse git command man page section_re = re.compile(r'^(?P<section>[A-Z].*)') option_re = re.compile(r'--?(?P<name>[a-zA-Z\-]+).*') + optopt_re = re.compile(r'--\[(?P<prefix>[a-zA-Z\-]+)\]-?') man_section = None for line in help.splitlines(): if man_section == "OPTIONS" and line.startswith(' -'): opts = line.split(',') for opt in opts: - match = option_re.match(opt.strip()) + opt = opt.strip() + match = optopt_re.match(opt) + if match: + opts.append(re.sub(optopt_re, '--', opt)) + prefix = match.group('prefix').strip('-') + opt = re.sub(optopt_re, '--%s-' % prefix, opt) + match = option_re.match(opt) if match and match.group('name') == feature: return True # Check man section |