|
15 | 15 | from termcolor import colored |
16 | 16 | import colorama # Required for Windows |
17 | 17 | import argcomplete |
18 | | -from glob import glob |
19 | 18 |
|
20 | 19 | __version__ = "1.0.0" |
21 | 20 | __client_specification__ = "1.3" |
@@ -223,17 +222,18 @@ def get_page(command, remote=None, platforms=None, languages=None): |
223 | 222 |
|
224 | 223 | COMMAND_SPLIT_REGEX = re.compile(r'(?P<param>{{.+?}})') |
225 | 224 | PARAM_REGEX = re.compile(r'(?:{{)(?P<param>.+?)(?:}})') |
226 | | -CACHE_FILE_REGEX = re.compile(r'.*\/(.*)\.md') |
227 | 225 |
|
228 | 226 |
|
229 | 227 | def get_commands(platforms=None): |
230 | 228 | if platforms is None: |
231 | 229 | platforms = get_platform_list() |
232 | 230 |
|
233 | | - cache_files = [] |
234 | | - for platform in platforms: |
235 | | - cache_files += glob(os.path.join(get_cache_dir(), 'pages', platform, '*.md')) |
236 | | - return [re.search(CACHE_FILE_REGEX, x).group(1) for x in cache_files] |
| 231 | + commands = [] |
| 232 | + if os.path.exists(get_cache_dir()): |
| 233 | + for platform in platforms: |
| 234 | + path = os.path.join(get_cache_dir(), 'pages', platform) |
| 235 | + commands += [file[:-3] for file in os.listdir(path) if file.endswith(".md")] |
| 236 | + return commands |
237 | 237 |
|
238 | 238 |
|
239 | 239 | def colors_of(key): |
@@ -269,7 +269,7 @@ def output(page): |
269 | 269 | colored( |
270 | 270 | line.replace('>', '').replace('<', ''), |
271 | 271 | *colors_of('description') |
272 | | - ) |
| 272 | + ) |
273 | 273 | sys.stdout.buffer.write(line.encode('utf-8')) |
274 | 274 | elif line[0] == '-': |
275 | 275 | line = '\n' + ' ' * LEADING_SPACES_NUM + \ |
@@ -381,9 +381,8 @@ def main(): |
381 | 381 | help='Override the default language') |
382 | 382 |
|
383 | 383 | parser.add_argument( |
384 | | - 'command', type=str, nargs='*', help="command to lookup", metavar='command', |
385 | | - choices=get_commands() + [[]] |
386 | | - ) |
| 384 | + 'command', type=str, nargs='*', help="command to lookup", metavar='command' |
| 385 | + ).completer = argcomplete.completers.ChoicesCompleter(get_commands() + [[]]) |
387 | 386 |
|
388 | 387 | argcomplete.autocomplete(parser) |
389 | 388 | options = parser.parse_args() |
|
0 commit comments