MCPcopy Index your code
hub / github.com/dbcli/pgcli / handle_watch_command

Method handle_watch_command

pgcli/main.py:1011–1037  ·  view source on GitHub ↗
(self, text)

Source from the content-addressed store, hash-verified

1009 print("Goodbye!")
1010
1011 def handle_watch_command(self, text):
1012 # Initialize default metaquery in case execution fails
1013 self.watch_command, timing = special.get_watch_command(text)
1014
1015 # If we run \watch without a command, apply it to the last query run.
1016 if self.watch_command is not None and not self.watch_command.strip():
1017 try:
1018 self.watch_command = self.query_history[-1].query
1019 except IndexError:
1020 click.secho("\\watch cannot be used with an empty query", err=True, fg="red")
1021 self.watch_command = None
1022
1023 # If there's a command to \watch, run it in a loop.
1024 if self.watch_command:
1025 while self.watch_command:
1026 try:
1027 query = self.execute_command(self.watch_command)
1028 click.echo(f"Waiting for {timing} seconds before repeating")
1029 sleep(timing)
1030 except KeyboardInterrupt:
1031 self.watch_command = None
1032
1033 # Otherwise, execute it as a regular command.
1034 else:
1035 query = self.execute_command(text)
1036
1037 self.query_history.append(query)
1038
1039 def _build_cli(self, history):
1040 key_bindings = pgcli_bindings(self)

Callers 3

run_cliMethod · 0.95
test_watch_worksFunction · 0.95
run_with_watchFunction · 0.80

Calls 2

execute_commandMethod · 0.95
echoMethod · 0.80

Tested by 2

test_watch_worksFunction · 0.76
run_with_watchFunction · 0.64