MCPcopy
hub / github.com/dbcli/pgcli / handle_editor_command

Method handle_editor_command

pgcli/main.py:775–811  ·  view source on GitHub ↗

r""" Editor command is any query that is prefixed or suffixed by a '\e'. The reason for a while loop is because a user might edit a query multiple times. For eg: "select * from \e" to edit it in vim, then come back to the prompt with the edited

(self, text)

Source from the content-addressed store, hash-verified

773 self.pgexecute = pgexecute
774
775 def handle_editor_command(self, text):
776 r"""
777 Editor command is any query that is prefixed or suffixed
778 by a '\e'. The reason for a while loop is because a user
779 might edit a query multiple times.
780 For eg:
781 "select * from \e"<enter> to edit it in vim, then come
782 back to the prompt with the edited query "select * from
783 blah where q = 'abc'\e" to edit it again.
784 :param text: Document
785 :return: Document
786 """
787 editor_command = special.editor_command(text)
788 while editor_command:
789 if editor_command == "\\e":
790 filename = special.get_filename(text)
791 query = special.get_editor_query(text) or self.get_last_query()
792 else: # \ev or \ef
793 filename = None
794 spec = text.split()[1]
795 if editor_command == "\\ev":
796 query = self.pgexecute.view_definition(spec)
797 elif editor_command == "\\ef":
798 query = self.pgexecute.function_definition(spec)
799 sql, message = special.open_external_editor(filename, sql=query)
800 if message:
801 # Something went wrong. Raise an exception and bail.
802 raise RuntimeError(message)
803 while True:
804 try:
805 text = self.prompt_app.prompt(default=sql)
806 break
807 except KeyboardInterrupt:
808 sql = ""
809
810 editor_command = special.editor_command(text)
811 return text
812
813 def execute_command(self, text, handle_closed_connection=True):
814 logger = self.logger

Callers 1

run_cliMethod · 0.95

Calls 3

get_last_queryMethod · 0.95
view_definitionMethod · 0.80
function_definitionMethod · 0.80

Tested by

no test coverage detected