|
18 | 18 | from spacy import tokens |
19 | 19 | from word2number import w2n |
20 | 20 |
|
| 21 | +import aclimatise |
21 | 22 | from aclimatise import cli_types |
22 | 23 | from aclimatise.cli_types import CliFileSystemType, CliString |
23 | 24 | from aclimatise.name_generation import generate_name, segment_string |
@@ -82,6 +83,37 @@ def __post_init__(self): |
82 | 83 | self.usage_flag = flag |
83 | 84 | self.named.remove(flag) |
84 | 85 |
|
| 86 | + def __getitem__(self, item: str) -> "Command": |
| 87 | + """ |
| 88 | + If present, returns a subcommand with the following name. For example, samtools_cmd['sort'] will return the |
| 89 | + "samtools sort" command |
| 90 | + """ |
| 91 | + for sub in self.subcommands: |
| 92 | + if sub.command == [*self.command, item]: |
| 93 | + return sub |
| 94 | + raise KeyError( |
| 95 | + "{} does not have a subcommand {}".format(" ".join(self.command), item) |
| 96 | + ) |
| 97 | + |
| 98 | + def reanalyse(self, parent: "Command" = None) -> "Command": |
| 99 | + """ |
| 100 | + Re-analyses the entire command tree using the existing help text but the current parser, and returns the new tree |
| 101 | + """ |
| 102 | + if len(self.subcommands) > 0: |
| 103 | + return Command( |
| 104 | + generated_using=self.generated_using, |
| 105 | + help_text=self.help_text, |
| 106 | + command=self.command, |
| 107 | + subcommands=[cmd.reanalyse(self) for cmd in self.subcommands], |
| 108 | + parent=parent, |
| 109 | + ) |
| 110 | + else: |
| 111 | + replacement = aclimatise.parse_help(cmd=self.command, text=self.help_text) |
| 112 | + replacement.parent = parent |
| 113 | + replacement.help_text = self.help_text |
| 114 | + replacement.generated_using = self.generated_using |
| 115 | + return replacement |
| 116 | + |
85 | 117 | @property |
86 | 118 | def outputs(self) -> typing.List["CliArgument"]: |
87 | 119 | """ |
|
0 commit comments