Tarantool development patches archive
 help / color / mirror / Atom feed
From: Cyrill Gorcunov <gorcunov@gmail.com>
To: tml <tarantool-patches@freelists.org>
Cc: Alexander Turenko <alexander.turenko@tarantool.org>,
	Kirill Yukhin <kyukhin@tarantool.org>,
	Konstantin Osipov <kostja@tarantool.org>,
	Cyrill Gorcunov <gorcunov@gmail.com>
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	[thread overview]
Message-ID: <20190723223113.16084-5-gorcunov@gmail.com> (raw)
In-Reply-To: <20190723223113.16084-1-gorcunov@gmail.com>

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

  parent reply	other threads:[~2019-07-23 22:32 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-23 22:31 [tarantool-patches] [PATCH v4 0/5] box/lua/console: Add initial support for lua output format Cyrill Gorcunov
2019-07-23 22:31 ` [tarantool-patches] [PATCH 1/5] third_party/serpent: Add serpent repo Cyrill Gorcunov
2019-07-24 17:02   ` [tarantool-patches] " Konstantin Osipov
2019-07-24 17:33     ` Cyrill Gorcunov
2019-07-23 22:31 ` [tarantool-patches] [PATCH 2/5] box/lua/console: Add support for lua output format Cyrill Gorcunov
2019-07-23 22:31 ` [tarantool-patches] [PATCH 3/5] box/lua/console: Don't serialize function body Cyrill Gorcunov
2019-07-23 22:31 ` Cyrill Gorcunov [this message]
2019-07-24 17:10   ` [tarantool-patches] Re: [PATCH 4/5] box/lua/console: Provide output_default function to setup default output Konstantin Osipov
2019-07-24 17:11     ` Konstantin Osipov
2019-07-24 17:34       ` Cyrill Gorcunov
2019-07-23 22:31 ` [tarantool-patches] [PATCH 5/5] box/lua/console: Limit lua output for local sessions only Cyrill Gorcunov
2019-07-24 17:15   ` [tarantool-patches] " Konstantin Osipov
2019-07-24 17:35     ` Cyrill Gorcunov
2019-07-24 17:00 ` [tarantool-patches] Re: [PATCH v4 0/5] box/lua/console: Add initial support for lua output format Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190723223113.16084-5-gorcunov@gmail.com \
    --to=gorcunov@gmail.com \
    --cc=alexander.turenko@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=kyukhin@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH 4/5] box/lua/console: Provide output_default function to setup default output' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox