(self, commandnode, parts, endword, addgroup=True)
| 362 | assert kind == node.kind |
| 363 | |
| 364 | def startcommand(self, commandnode, parts, endword, addgroup=True): |
| 365 | logger.info( |
| 366 | "startcommand commandnode=%r parts=%r, endword=%r, addgroup=%s", |
| 367 | commandnode, |
| 368 | parts, |
| 369 | endword, |
| 370 | addgroup, |
| 371 | ) |
| 372 | idx_word_node = bashlex.ast.findfirstkind(parts, "word") |
| 373 | assert idx_word_node != -1 |
| 374 | |
| 375 | word_node = parts[idx_word_node] |
| 376 | if word_node.parts: |
| 377 | logger.info( |
| 378 | "node %r has parts (it was expanded), no point in looking" |
| 379 | " up a manpage for it", |
| 380 | word_node, |
| 381 | ) |
| 382 | |
| 383 | if addgroup: |
| 384 | mg = MatchGroup(self._generate_cmd_group_name()) |
| 385 | mg.manpage = None |
| 386 | mg.suggestions = None |
| 387 | self.groups.append(mg) |
| 388 | self.group_stack.append((commandnode, mg, endword)) |
| 389 | |
| 390 | return False |
| 391 | |
| 392 | startpos, endpos = word_node.pos |
| 393 | |
| 394 | try: |
| 395 | mps = self.find_man_pages(word_node.word) |
| 396 | # we consume this node here, pop it from parts so we |
| 397 | # don't visit it again as an argument |
| 398 | parts.pop(idx_word_node) |
| 399 | except errors.ProgramDoesNotExist as error_msg: |
| 400 | if addgroup: |
| 401 | # add a group for this command, we'll mark it as unknown |
| 402 | # when visitword is called |
| 403 | logger.info( |
| 404 | f"no manpage found for {word_node.word}, adding a group for it" |
| 405 | ) |
| 406 | |
| 407 | mg = MatchGroup(self._generate_cmd_group_name()) |
| 408 | mg.error = error_msg |
| 409 | mg.manpage = None |
| 410 | mg.suggestions = None |
| 411 | self.groups.append(mg) |
| 412 | self.group_stack.append((commandnode, mg, endword)) |
| 413 | |
| 414 | return False |
| 415 | |
| 416 | manpage = mps[0] |
| 417 | idx_next_word_node = bashlex.ast.findfirstkind(parts, "word") |
| 418 | |
| 419 | # check the next word for a possible subcommand if: |
| 420 | # - the matched manpage says so |
| 421 | # - we have another word node |
no test coverage detected