From a738c580224e340f011ffa174a9f1259521120cd Mon Sep 17 00:00:00 2001 From: Jacob Becker Date: Fri, 17 Apr 2020 21:41:36 -0700 Subject: [PATCH] cqlsh return non-zero status when STDIN CQL fails Patch By Jacob Becker a.k.a. plastikat; reviewed by Jordan West and Dinesh Joshi for CASSANDRA-15623 --- CHANGES.txt | 1 + bin/cqlsh.py | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 91b8241ee7..8d1c8efe04 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 3.0.21 + * cqlsh return non-zero status when STDIN CQL fails (CASSANDRA-15623) * Don't skip sstables in slice queries based only on local min/max/deletion timestamp (CASSANDRA-15690) * Memtable memory allocations may deadlock (CASSANDRA-15367) * Run evictFromMembership in GossipStage (CASSANDRA-15592) diff --git a/bin/cqlsh.py b/bin/cqlsh.py index 08b026cca9..2477766585 100644 --- a/bin/cqlsh.py +++ b/bin/cqlsh.py @@ -813,6 +813,10 @@ class Shell(cmd.Cmd): self.statement_error = False self.single_statement = single_statement + @property + def batch_mode(self): + return not self.tty + @property def is_using_utf8(self): # utf8 encodings from https://docs.python.org/{2,3}/library/codecs.html @@ -2681,8 +2685,8 @@ def main(options, hostname, port): shell.cmdloop() save_history() - batch_mode = options.file or options.execute - if batch_mode and shell.statement_error: + + if shell.batch_mode and shell.statement_error: sys.exit(2)