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 4230F20A69 for ; Wed, 25 Jul 2018 03:51:41 -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 Kstz4g7N-FX7 for ; Wed, 25 Jul 2018 03:51:41 -0400 (EDT) Received: from smtp43.i.mail.ru (smtp43.i.mail.ru [94.100.177.103]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id A4BF920A5F for ; Wed, 25 Jul 2018 03:51:40 -0400 (EDT) Received: from [185.6.245.156] (port=6848 helo=mimeev-ThinkPad-T460p.mail.msk) by smtp43.i.mail.ru with esmtpa (envelope-from ) id 1fiEaA-0005a8-Ng for tarantool-patches@freelists.org; Wed, 25 Jul 2018 10:51:38 +0300 From: imeevma@tarantool.org Subject: [tarantool-patches] [PATCH v1 1/1] Tarantoolctl "enter" with set language Date: Wed, 25 Jul 2018 10:51:37 +0300 Message-Id: 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: tarantool-patches@freelists.org This patch allow to use option "--language" with "tarantoolctl enter" command. Also default value for language were added in default configuration file. Language is either SQL or Lua. Closes #2385. --- Branch: https://github.com/tarantool/tarantool/tree/imeevma/gh-2385-select-input-language-tarantoolctl Issue: https://github.com/tarantool/tarantool/issues/2385 extra/dist/CMakeLists.txt | 1 + extra/dist/default/tarantool.in | 1 + extra/dist/tarantoolctl.in | 22 +++++++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/extra/dist/CMakeLists.txt b/extra/dist/CMakeLists.txt index 862689e..3045b5a 100644 --- a/extra/dist/CMakeLists.txt +++ b/extra/dist/CMakeLists.txt @@ -34,6 +34,7 @@ message (STATUS "tarantoolctl logdir: ${TARANTOOL_LOGDIR}") set(TARANTOOL_RUNDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run/tarantool") message (STATUS "tarantoolctl rundir: ${TARANTOOL_RUNDIR}") set(TARANTOOL_USER "tarantool") +set(TARANTOOL_LANGUAGE "lua") set(SYSCONFIG_AVAILABLEDIR "tarantool/instances.available") set(SYSCONFIG_ENABLEDDIR "tarantool/instances.enabled") set(TARANTOOL_AVAILABLEDIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/${SYSCONFIG_AVAILABLEDIR}") diff --git a/extra/dist/default/tarantool.in b/extra/dist/default/tarantool.in index 9a8dad3..01e7144 100644 --- a/extra/dist/default/tarantool.in +++ b/extra/dist/default/tarantool.in @@ -20,6 +20,7 @@ default_cfg = { vinyl_dir = "@TARANTOOL_DATADIR@", -- @TARANTOOL_DATADIR@/${INSTANCE} log = "@TARANTOOL_LOGDIR@", -- @TARANTOOL_LOGDIR@/${INSTANCE}.log username = "@TARANTOOL_USER@", + language = "@TARANTOOL_LANGUAGE@", } -- instances.available - all available instances diff --git a/extra/dist/tarantoolctl.in b/extra/dist/tarantoolctl.in index 2dd5d74..55711b8 100755 --- a/extra/dist/tarantoolctl.in +++ b/extra/dist/tarantoolctl.in @@ -155,6 +155,11 @@ local function load_default_file(default_file) d.vinyl_dir = fio.pathjoin(d.vinyl_dir, instance_name) d.log = fio.pathjoin(d.log, instance_name .. '.log') + d.language = (d.language or "lua"):lower() + if d.language ~= "lua" and d.language ~= "sql" then + d.language = "lua" + end + default_cfg = d if not usermode then @@ -454,6 +459,7 @@ local function wrapper_cfg(cfg) elseif cfg.background == nil then cfg.background = true end + cfg.language = nil mk_default_dirs(cfg) local success, data = pcall(orig_cfg, cfg) @@ -629,6 +635,17 @@ local function logrotate() end local function enter() + local options = keyword_arguments + local language = options.language + if language ~= nil then + language = language:lower() + if language ~= "lua" and language ~= "sql" then + log.warn("Language \"%s\" is not recognized. Default language" .. + " \"%s\" is set.", language, default_cfg.language) + language = nil + end + end + language = language or default_cfg.language local console_sock_path = uri.parse(console_sock).service if fio.stat(console_sock_path) == nil then log.error("Can't connect to %s (%s)", console_sock_path, errno.strerror()) @@ -644,7 +661,9 @@ local function enter() console_sock, TIMEOUT_INFINITY ) - console.on_start(function(self) self:eval(cmd) end) + local cmd_language = string.format("\\set language %s", language) + + console.on_start(function(self) self:eval(cmd) self:eval(cmd_language) end) console.on_client_disconnect(function(self) self.running = false end) console.start() return 0 @@ -1284,6 +1303,7 @@ do { 'chdir', 'string' }, { 'only-server', 'string' }, { 'server', 'string' }, + { 'language', 'string' }, }) local cmd_name -- 2.7.4