| 117 | |
| 118 | |
| 119 | class MainArgParser(CLIArgParser): |
| 120 | Formatter = argparse.RawTextHelpFormatter |
| 121 | |
| 122 | def __init__( |
| 123 | self, |
| 124 | command_table, |
| 125 | version_string, |
| 126 | description, |
| 127 | argument_table, |
| 128 | prog=None, |
| 129 | ): |
| 130 | super().__init__( |
| 131 | formatter_class=self.Formatter, |
| 132 | add_help=False, |
| 133 | conflict_handler='resolve', |
| 134 | description=description, |
| 135 | usage=USAGE, |
| 136 | prog=prog, |
| 137 | ) |
| 138 | self._build(command_table, version_string, argument_table) |
| 139 | |
| 140 | def _create_choice_help(self, choices): |
| 141 | help_str = '' |
| 142 | for choice in sorted(choices): |
| 143 | help_str += f'* {choice}\n' |
| 144 | return help_str |
| 145 | |
| 146 | def _build(self, command_table, version_string, argument_table): |
| 147 | for argument_name in argument_table: |
| 148 | argument = argument_table[argument_name] |
| 149 | argument.add_to_parser(self) |
| 150 | self.add_argument( |
| 151 | '--version', |
| 152 | action="version", |
| 153 | version=version_string, |
| 154 | help='Display the version of this tool', |
| 155 | ) |
| 156 | self.add_argument( |
| 157 | 'command', action=CommandAction, command_table=command_table |
| 158 | ) |
| 159 | |
| 160 | |
| 161 | class ServiceArgParser(CLIArgParser): |
no outgoing calls