From 8abe9f6f522146dc478f006a8160b4db1c233169 Mon Sep 17 00:00:00 2001 From: Mikhail Stepura Date: Thu, 8 May 2014 13:20:35 -0700 Subject: [PATCH] cqlsh should return a non-zero error code if a query fails patch by Branden Visser and Mikhail Stepura; reviewed by Mikhail Stepura for CASSANDRA-6344 --- CHANGES.txt | 1 + bin/cqlsh | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/CHANGES.txt b/CHANGES.txt index 312cf06b6a..7021e7b3fa 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -23,6 +23,7 @@ * remove duplicate query for local tokens (CASSANDRA-7182) * raise streaming phi convict threshold level (CASSANDRA-7063) * reduce garbage creation in calculatePendingRanges (CASSANDRA-7191) + * exit CQLSH with error status code if script fails (CASSANDRA-6344) 1.2.16 * Add UNLOGGED, COUNTER options to BATCH documentation (CASSANDRA-6816) diff --git a/bin/cqlsh b/bin/cqlsh index 8e1e0e20b1..24cb3b8bf4 100755 --- a/bin/cqlsh +++ b/bin/cqlsh @@ -548,6 +548,7 @@ class Shell(cmd.Cmd): self.show_line_nums = True self.stdin = stdin self.query_out = sys.stdout + self.statement_error = False def set_expanded_cql_version(self, ver): ver, vertuple = full_cql_version(ver) @@ -2175,6 +2176,7 @@ class Shell(cmd.Cmd): self.query_out.flush() def printerr(self, text, color=RED, newline=True, shownum=None): + self.statement_error = True if shownum is None: shownum = self.show_line_nums if shownum: @@ -2404,6 +2406,8 @@ def main(options, hostname, port): shell.cmdloop() save_history() + if options.file and shell.statement_error: + sys.exit(2) if __name__ == '__main__': main(*read_options(sys.argv[1:], os.environ))