| 11 | |
| 12 | @with_default_category('Query Category') |
| 13 | class QueryCommandSet(CommandSet, ArgumentsManager): |
| 14 | def __init__(self, args) -> None: |
| 15 | super().__init__() |
| 16 | if args is not None: |
| 17 | if args.config: |
| 18 | Settings.load_settings(args.config) |
| 19 | self._filter_options = Settings.filter_options |
| 20 | self._config = ResultSetting() |
| 21 | self._core = DataManager() |
| 22 | self._remove_default_commands() |
| 23 | |
| 24 | def close_connection(self): |
| 25 | if self._core: |
| 26 | self._core.close() |
| 27 | |
| 28 | |
| 29 | parser = Cmd2ArgumentParser(add_help="") |
| 30 | subparser = parser.add_subparsers(dest='section', required=True) |
| 31 | |
| 32 | format_parser = subparser.add_parser('format') |
| 33 | format_parser.add_argument('value', choices=Settings.valid_format_files) |
| 34 | |
| 35 | database_parser = subparser.add_parser('database') |
| 36 | database_parser.add_argument('value') |
| 37 | |
| 38 | output_parser = subparser.add_parser('output') |
| 39 | output_parser.add_argument('value') |
| 40 | |
| 41 | def _remove_default_commands(self): |
| 42 | for command in Settings.get_default_commands(): |
| 43 | if hasattr(cmd2.Cmd, command): |
| 44 | delattr(cmd2.Cmd, command) |
| 45 | |
| 46 | |
| 47 | @with_argparser(parser) |
| 48 | def do_set(self, arg): |
| 49 | if arg.section != 'database': |
| 50 | ResultSetting().set_value(arg.section,arg.value) |
| 51 | else: |
| 52 | SqlMapSetting().set_value(arg.section,arg.value) |
| 53 | |
| 54 | def complete_search(self, text, line, begidx, endidx): |
| 55 | completions = [] |
| 56 | hashes = list(Hashes.get_available_algorithms()) |
| 57 | for hash in hashes: |
| 58 | if hash.startswith(text): |
| 59 | completions.append(hash) |
| 60 | |
| 61 | for item in Settings.filter_options: |
| 62 | if item.startswith(text): |
| 63 | completions.append(item) |
| 64 | |
| 65 | return completions |
| 66 | |
| 67 | |
| 68 | def do_clean(self, arg): |
| 69 | self._core.clean() |
| 70 | |