From f8a5ac5337702119cb0f285879953cbdeceaeb20 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 18 Aug 2013 13:05:32 +0200 Subject: add alternative mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/argparser.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/argparser.py') diff --git a/src/argparser.py b/src/argparser.py index d9f9d55..93b0287 100644 --- a/src/argparser.py +++ b/src/argparser.py @@ -176,12 +176,13 @@ class ArgParser(): self.optmap[alt] = (stdalt, ArgParser.VARIADIC) - def parse(self, argv = sys.argv): + def parse(self, argv = sys.argv, alternative = False): ''' Parse arguments - @param args:list The command line arguments, should include the execute file at index 0, `sys.argv` is default - @return :bool Whether no unrecognised option is used + @param args:list The command line arguments, should include the execute file at index 0, `sys.argv` is default + @param alternative:bool Use single dash/plus for long options + @return :bool Whether no unrecognised option is used ''' self.argcount = len(argv) - 1 self.arguments = argv[1:] @@ -220,7 +221,7 @@ class ArgParser(): elif arg == '++': tmpdashed = True elif arg == '--': dashed = True elif (len(arg) > 1) and (arg[0] in ('-', '+')): - if (len(arg) > 2) and (arg[:2] in ('--', '++')): + if alternative or ((len(arg) > 2) and (arg[:2] in ('--', '++'))): if dontget > 0: dontget -= 1 elif (arg in self.optmap) and (self.optmap[arg][1] == ArgParser.ARGUMENTLESS): -- cgit v1.2.3-70-g09d2