aboutsummaryrefslogtreecommitdiffstats
path: root/auto-auto-complete.py
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2012-10-28 21:35:52 +0100
committerMattias Andrée <maandree@operamail.com>2012-10-28 21:35:52 +0100
commite4fe6a0bb7020c7d189590e8bf767d82cbb1c0db (patch)
treeb1c611dcdba59e929203de7ef6911c8a3601fcc0 /auto-auto-complete.py
parentuse reflection to get a generator for the specified shell (diff)
downloadauto-auto-complete-e4fe6a0bb7020c7d189590e8bf767d82cbb1c0db.tar.gz
auto-auto-complete-e4fe6a0bb7020c7d189590e8bf767d82cbb1c0db.tar.bz2
auto-auto-complete-e4fe6a0bb7020c7d189590e8bf767d82cbb1c0db.tar.xz
invokable from another python file
Diffstat (limited to '')
-rwxr-xr-xauto-auto-complete.py78
1 files changed, 45 insertions, 33 deletions
diff --git a/auto-auto-complete.py b/auto-auto-complete.py
index 4280e61..a38ee94 100755
--- a/auto-auto-complete.py
+++ b/auto-auto-complete.py
@@ -180,13 +180,56 @@ class GeneratorBASH:
'''
mane!
+
+@param shell:str Shell to generato completion for
+@param output:str Output file
+@param source:str Source file
+'''
+def main(shell, outputm source)
+ with open(source, 'rb') as file:
+ source = file.read().decode('utf8', 'replace')
+ source = Parser.parse(source)
+ Parser.simplify(source)
+
+ program = source[0]
+ unargumented = []
+ argumented = []
+ variadic = []
+ suggestion = []
+
+ for item in source[1:]:
+ if item[0] == 'unargumented':
+ unargumented.append(item[1:]);
+ elif item[0] == 'argumented':
+ argumented.append(item[1:]);
+ elif item[0] == 'variadic':
+ variadic.append(item[1:]);
+ elif item[0] == 'suggestion':
+ suggestion.append(item[1:]);
+
+ for group in (unargumented, argumented, variadic):
+ for index in range(0, len(group)):
+ item = group[index]
+ map = {}
+ for elem in item:
+ map[elem[0]] = elem[1:]
+ group[index] = map
+
+ generator = 'Generator' + shell.upper()
+ generator = globals()[generator]
+ generator = generator(program, unargumented, argumented, variadic, suggestion)
+
+
+
+'''
+mane!
'''
if __name__ == '__main__':
if len(sys.argv) != 6:
print("USAGE: auto-auto-complete SHELL --output OUTPUT_FILE --source SOURCE_FILE")
exit(1)
- shell = sys.argv[1].upper()
+ shell = sys.argv[1]
output = None
source = None
@@ -221,36 +264,5 @@ if __name__ == '__main__':
if output is None: raise Exception('Unused option: --output')
if source is None: raise Exception('Unused option: --source')
- with open(source, 'rb') as file:
- source = file.read().decode('utf8', 'replace')
- source = Parser.parse(source)
- Parser.simplify(source)
-
- program = source[0]
- unargumented = []
- argumented = []
- variadic = []
- suggestion = []
-
- for item in source[1:]:
- if item[0] == 'unargumented':
- unargumented.append(item[1:]);
- elif item[0] == 'argumented':
- argumented.append(item[1:]);
- elif item[0] == 'variadic':
- variadic.append(item[1:]);
- elif item[0] == 'suggestion':
- suggestion.append(item[1:]);
-
- for group in (unargumented, argumented, variadic):
- for index in range(0, len(group)):
- item = group[index]
- map = {}
- for elem in item:
- map[elem[0]] = elem[1:]
- group[index] = map
-
- generator = 'Generator' + shell
- generator = globals()[generator]
- generator = generator(program, unargumented, argumented, variadic, suggestion)
+ main(shell= shell, output= output, source= source)