From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id BB26625245 for ; Tue, 23 Jul 2019 18:32:02 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5T40hBBI51kI for ; Tue, 23 Jul 2019 18:32:02 -0400 (EDT) Received: from mail-lf1-f67.google.com (mail-lf1-f67.google.com [209.85.167.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 5471F24119 for ; Tue, 23 Jul 2019 18:32:02 -0400 (EDT) Received: by mail-lf1-f67.google.com with SMTP id v85so30449490lfa.6 for ; Tue, 23 Jul 2019 15:32:02 -0700 (PDT) From: Cyrill Gorcunov Subject: [tarantool-patches] [PATCH 4/5] box/lua/console: Provide output_default function to setup default output Date: Wed, 24 Jul 2019 01:31:12 +0300 Message-Id: <20190723223113.16084-5-gorcunov@gmail.com> In-Reply-To: <20190723223113.16084-1-gorcunov@gmail.com> References: <20190723223113.16084-1-gorcunov@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tml Cc: Alexander Turenko , Kirill Yukhin , Konstantin Osipov , Cyrill Gorcunov A user might need to use lua output as default serializer so instead of requiring him setting up the output every new session that named default output mode may be used instead with help of command > require('console').set_default_output("lua") Also we provide > require('console').get_default_output("lua") to obtain current setting. Part-of #3834 --- src/box/lua/console.lua | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/box/lua/console.lua b/src/box/lua/console.lua index 7120bc8e6..db57a6d80 100644 --- a/src/box/lua/console.lua +++ b/src/box/lua/console.lua @@ -14,6 +14,10 @@ local net_box = require('net.box') local YAML_TERM = '\n...\n' local PUSH_TAG_HANDLE = '!push!' +-- +-- Default output handler set to YAML for backward +-- compatibility reason. +local ouput_default_handler = { ["fmt"] = "yaml", ["opts"] = nil } local output_handlers = { } output_handlers["yaml"] = function(status, opts, ...) @@ -99,6 +103,22 @@ local function output_parse(value) return false, msg:format(value) end +local function set_default_output(value) + if value == nil then + error("Nil output value passed") + end + local status, err, fmt, opts = output_parse(value) + if status ~= true then + error(err) + end + ouput_default_handler["fmt"] = fmt + ouput_default_handler["opts"] = opts +end + +local function get_default_output(value) + return ouput_default_handler +end + local function output_save(fmt, opts) -- -- Output format descriptors are saved per @@ -111,14 +131,8 @@ end local function format(status, ...) local d = box.session.storage.console_output - -- - -- If there was no assignment yet provide - -- a default value; for now it is YAML - -- for backward compatibility sake (don't - -- forget about test results which are in - -- YAML format). if d == nil then - d = { ["fmt"] = "yaml", ["opts"] = nil } + d = ouput_default_handler end return output_handlers[d["fmt"]](status, d["opts"], ...) end @@ -674,6 +688,8 @@ package.loaded['console'] = { start = start; eval = eval; delimiter = delimiter; + set_default_output = set_default_output; + get_default_output = get_default_output; ac = ac; connect = connect; listen = listen; -- 2.20.1