@@ -185,12 +185,14 @@ def __init__(
185185 warn = None ,
186186 ssh_tunnel_url : Optional [str ] = None ,
187187 log_file : Optional [str ] = None ,
188+ force_destructive : bool = False ,
188189 ):
189190 self .force_passwd_prompt = force_passwd_prompt
190191 self .never_passwd_prompt = never_passwd_prompt
191192 self .pgexecute = pgexecute
192193 self .dsn_alias = None
193194 self .watch_command = None
195+ self .force_destructive = force_destructive
194196
195197 # Load config.
196198 c = self .config = get_config (pgclirc_file )
@@ -484,7 +486,10 @@ def execute_from_file(self, pattern, **_):
484486 ):
485487 message = "Destructive statements must be run within a transaction. Command execution stopped."
486488 return [(None , None , None , message )]
487- destroy = confirm_destructive_query (query , self .destructive_warning , self .dsn_alias )
489+ if self .force_destructive :
490+ destroy = True
491+ else :
492+ destroy = confirm_destructive_query (query , self .destructive_warning , self .dsn_alias )
488493 if destroy is False :
489494 message = "Wise choice. Command execution stopped."
490495 return [(None , None , None , message )]
@@ -792,7 +797,10 @@ def execute_command(self, text, handle_closed_connection=True):
792797 ):
793798 click .secho ("Destructive statements must be run within a transaction." )
794799 raise KeyboardInterrupt
795- destroy = confirm_destructive_query (text , self .destructive_warning , self .dsn_alias )
800+ if self .force_destructive :
801+ destroy = True
802+ else :
803+ destroy = confirm_destructive_query (text , self .destructive_warning , self .dsn_alias )
796804 if destroy is False :
797805 click .secho ("Wise choice!" )
798806 raise KeyboardInterrupt
@@ -1426,6 +1434,14 @@ def echo_via_pager(self, text, color=None):
14261434 type = str ,
14271435 help = "SQL statement to execute after connecting." ,
14281436)
1437+ @click .option (
1438+ "-y" ,
1439+ "--yes" ,
1440+ "force_destructive" ,
1441+ is_flag = True ,
1442+ default = False ,
1443+ help = "Force destructive commands without confirmation prompt." ,
1444+ )
14291445@click .argument ("dbname" , default = lambda : None , envvar = "PGDATABASE" , nargs = 1 )
14301446@click .argument ("username" , default = lambda : None , envvar = "PGUSER" , nargs = 1 )
14311447def cli (
@@ -1454,6 +1470,7 @@ def cli(
14541470 ssh_tunnel : str ,
14551471 init_command : str ,
14561472 log_file : str ,
1473+ force_destructive : bool ,
14571474):
14581475 if version :
14591476 print ("Version:" , __version__ )
@@ -1512,6 +1529,7 @@ def cli(
15121529 warn = warn ,
15131530 ssh_tunnel_url = ssh_tunnel ,
15141531 log_file = log_file ,
1532+ force_destructive = force_destructive ,
15151533 )
15161534
15171535 # Choose which ever one has a valid value.
0 commit comments