MCPcopy Index your code
hub / github.com/dbcli/mycli / main_execute_from_cli

Function main_execute_from_cli

mycli/main_modes/execute.py:16–55  ·  view source on GitHub ↗
(mycli: 'MyCli', cli_args: 'CliArgs')

Source from the content-addressed store, hash-verified

14
15
16def main_execute_from_cli(mycli: 'MyCli', cli_args: 'CliArgs') -> int:
17 if cli_args.execute is None:
18 return 1
19 if not sys.stdin.isatty():
20 click.secho('Ignoring STDIN since --execute was also given.', err=True, fg='red')
21 if cli_args.batch:
22 click.secho('Ignoring --batch since --execute was also given.', err=True, fg='red')
23 try:
24 execute_sql = cli_args.execute
25 if cli_args.format == 'csv':
26 mycli.main_formatter.format_name = 'csv'
27 if execute_sql.endswith(r'\G'):
28 execute_sql = execute_sql[:-2]
29 elif cli_args.format == 'tsv':
30 mycli.main_formatter.format_name = 'tsv'
31 if execute_sql.endswith(r'\G'):
32 execute_sql = execute_sql[:-2]
33 elif cli_args.format == 'table':
34 mycli.main_formatter.format_name = 'ascii'
35 if execute_sql.endswith(r'\G'):
36 execute_sql = execute_sql[:-2]
37 else:
38 mycli.main_formatter.format_name = 'tsv'
39
40 execution_confirmed: bool | None = True
41 if cli_args.warn_batch and is_destructive(mycli.destructive_keywords, execute_sql):
42 try:
43 sys.stdin = open('/dev/tty')
44 execution_confirmed = confirm_destructive_query(mycli.destructive_keywords, execute_sql)
45 except (IOError, OSError) as e:
46 mycli.logger.warning('Unable to open TTY as stdin.')
47 raise e
48 if execution_confirmed:
49 mycli.run_query(execute_sql, checkpoint=cli_args.checkpoint)
50 return 0
51 else:
52 return 1
53 except Exception as e:
54 click.secho(str(e), err=True, fg="red")
55 return 1

Callers 1

run_from_cli_argsFunction · 0.90

Calls 5

is_destructiveFunction · 0.90
isattyMethod · 0.80
warningMethod · 0.45
run_queryMethod · 0.45

Tested by

no test coverage detected