<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<div class="moz-text-flowed" style="font-family: -moz-fixed;
font-size: 12px;" lang="x-unicode">
<br>
<br>
On 07/26/2018 12:56 AM, Vladislav Shpilevoy wrote:
<br>
<blockquote type="cite" style="color: #000000;">
<br>
<br>
On 25/07/2018 10:51, <a class="moz-txt-link-abbreviated"
href="mailto:imeevma@tarantool.org">imeevma@tarantool.org</a>
wrote:
<br>
<blockquote type="cite" style="color: #000000;">This patch allow
to use option "--language" with
<br>
"tarantoolctl enter" command. Also default value
<br>
for language were added in default configuration
<br>
file. Language is either SQL or Lua.
<br>
<br>
Closes #2385.
<br>
---
<br>
Branch: <a class="moz-txt-link-freetext"
href="https://github.com/tarantool/tarantool/tree/imeevma/gh-2385-select-input-language-tarantoolctl">https://github.com/tarantool/tarantool/tree/imeevma/gh-2385-select-input-language-tarantoolctl</a>
<br>
Issue: <a class="moz-txt-link-freetext"
href="https://github.com/tarantool/tarantool/issues/2385">https://github.com/tarantool/tarantool/issues/2385</a>
<br>
<br>
diff --git a/extra/dist/tarantoolctl.in
b/extra/dist/tarantoolctl.in
<br>
index 2dd5d74..55711b8 100755
<br>
--- a/extra/dist/tarantoolctl.in
<br>
+++ b/extra/dist/tarantoolctl.in
<br>
@@ -155,6 +155,11 @@ local function
load_default_file(default_file)
<br>
d.vinyl_dir = fio.pathjoin(d.vinyl_dir, instance_name)
<br>
d.log = fio.pathjoin(d.log, instance_name ..
'.log')
<br>
+ d.language = (d.language or "lua"):lower()
<br>
+ if d.language ~= "lua" and d.language ~= "sql" then
<br>
+ d.language = "lua"
<br>
</blockquote>
<br>
1. Please, do not ignore unknown language. Log this error like
others
<br>
in the same function already do.
<br>
</blockquote>
Done.
<br>
<blockquote type="cite" style="color: #000000;">
<br>
2. Why do you need language in default_cfg? It is box.cfg as I
<br>
understand and box.cfg has no language option. It is not? If you
<br>
need to parse a language from the file, then you can store it in
<br>
another table or even in a separate variable like others on
lines
<br>
30-49.
<br>
</blockquote>
Done.
<br>
<blockquote type="cite" style="color: #000000;">
<br>
<blockquote type="cite" style="color: #000000;">+ end
<br>
+
<br>
default_cfg = d
<br>
if not usermode the> @@ -629,6 +635,17 @@ local
function logrotate()
<br>
end
<br>
local function enter()
<br>
+ local options = keyword_arguments
<br>
+ local language = options.language
<br>
+ if language ~= nil then
<br>
+ language = language:lower()
<br>
+ if language ~= "lua" and language ~= "sql" then
<br>
+ log.warn("Language \"%s\" is not recognized.
Default language" ..
<br>
+ " \"%s\" is set.", language,
default_cfg.language)
<br>
+ language = nil
<br>
</blockquote>
<br>
3. For enter() function it is ok to fail on unknown language.
<br>
You should not ignore the error because a caller could use
<br>
something like this:
<br>
<br>
cat my_script.sql | tarantoolctl enter --language sqlll
<br>
<br>
And if you ignore invalid language, this command will feed the
<br>
entire script on SQL into Lua console. It will produce huge
<br>
number of syntax errors if no worse.
<br>
</blockquote>
Done.
<br>
<blockquote type="cite" style="color: #000000;">
<br>
<blockquote type="cite" style="color: #000000;">+ end
<br>
+ end
<br>
+ language = language or default_cfg.language
<br>
local console_sock_path =
uri.parse(console_sock).service
<br>
if fio.stat(console_sock_path) == nil then
<br>
log.error("Can't connect to %s (%s)",
console_sock_path, errno.strerror())
<br>
@@ -644,7 +661,9 @@ local function enter()
<br>
console_sock, TIMEOUT_INFINITY
<br>
)
<br>
- console.on_start(function(self) self:eval(cmd) end)
<br>
+ local cmd_language = string.format("\\set language %s",
language)
<br>
</blockquote>
<br>
4. Why not to merge cmd_language into cmd? It is created a line
above.
<br>
</blockquote>
Discussed, partly changed.
<br>
<blockquote type="cite" style="color: #000000;">
<br>
<blockquote type="cite" style="color: #000000;">+
<br>
+ console.on_start(function(self) self:eval(cmd)
self:eval(cmd_language) end)
<br>
console.on_client_disconnect(function(self) self.running
= false end)
<br>
console.start()
<br>
return 0
<br>
@@ -1284,6 +1303,7 @@ do
<br>
{ 'chdir', 'string' },
<br>
{ 'only-server', 'string' },
<br>
{ 'server', 'string' },
<br>
+ { 'language', 'string' },
<br>
})
<br>
local cmd_name
<br>
<br>
</blockquote>
<br>
5. Lets add the same option to 'eval', 'connect' to make the
commands
<br>
symmetric.
<br>
</blockquote>
Discussed, decided to reject the idea.
<br>
<blockquote type="cite" style="color: #000000;">
<br>
6. Please, update the comments. For example, on line 1028 I
<br>
still see the comment about 'enter': "Enter an instance's
interactive Lua console",
<br>
but actually it is not complete now - you can choose SQL.
<br>
<br>
</blockquote>
Done.
<br>
<br>
commit 7088606bba3810ffc6db313cf31d7aa101d7175d
<br>
Author: Mergen Imeev <a class="moz-txt-link-rfc2396E"
href="mailto:imeevma@gmail.com"><imeevma@gmail.com></a>
<br>
Date: Fri Jul 13 19:25:32 2018 +0300
<br>
<br>
Tarantoolctl "enter" with set language
<br>
<br>
This patch allow to use option "--language" with
<br>
"tarantoolctl enter" command. Also default value
<br>
for language were added in default configuration
<br>
file. Language is either SQL or Lua.
<br>
<br>
Closes #2385.
<br>
<br>
diff --git a/extra/dist/CMakeLists.txt b/extra/dist/CMakeLists.txt
<br>
index 862689e..3045b5a 100644
<br>
--- a/extra/dist/CMakeLists.txt
<br>
+++ b/extra/dist/CMakeLists.txt
<br>
@@ -34,6 +34,7 @@ message (STATUS "tarantoolctl logdir:
${TARANTOOL_LOGDIR}")
<br>
set(TARANTOOL_RUNDIR
"${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/run/tarantool")
<br>
message (STATUS "tarantoolctl rundir: ${TARANTOOL_RUNDIR}")
<br>
set(TARANTOOL_USER "tarantool")
<br>
+set(TARANTOOL_LANGUAGE "lua")
<br>
set(SYSCONFIG_AVAILABLEDIR "tarantool/instances.available")
<br>
set(SYSCONFIG_ENABLEDDIR "tarantool/instances.enabled")
<br>
set(TARANTOOL_AVAILABLEDIR
"${CMAKE_INSTALL_FULL_SYSCONFDIR}/${SYSCONFIG_AVAILABLEDIR}")
<br>
diff --git a/extra/dist/default/tarantool.in
b/extra/dist/default/tarantool.in
<br>
index 9a8dad3..01e7144 100644
<br>
--- a/extra/dist/default/tarantool.in
<br>
+++ b/extra/dist/default/tarantool.in
<br>
@@ -20,6 +20,7 @@ default_cfg = {
<br>
vinyl_dir = "@TARANTOOL_DATADIR@", --
@TARANTOOL_DATADIR@/${INSTANCE}
<br>
log = "@TARANTOOL_LOGDIR@", --
@TARANTOOL_LOGDIR@/${INSTANCE}.log
<br>
username = "@TARANTOOL_USER@",
<br>
+ language = "@TARANTOOL_LANGUAGE@",
<br>
}
<br>
<br>
-- instances.available - all available instances
<br>
diff --git a/extra/dist/tarantoolctl.in
b/extra/dist/tarantoolctl.in
<br>
index 2dd5d74..ef9da2f 100755
<br>
--- a/extra/dist/tarantoolctl.in
<br>
+++ b/extra/dist/tarantoolctl.in
<br>
@@ -47,6 +47,7 @@ local default_cfg
<br>
local positional_arguments
<br>
local keyword_arguments
<br>
local lua_arguments = arg
<br>
+local language
<br>
<br>
-- function for printing usage reference
<br>
local usage
<br>
@@ -155,6 +156,14 @@ local function
load_default_file(default_file)
<br>
d.vinyl_dir = fio.pathjoin(d.vinyl_dir, instance_name)
<br>
d.log = fio.pathjoin(d.log, instance_name ..
'.log')
<br>
<br>
+ language = (d.language or "lua"):lower()
<br>
+ d.language = nil
<br>
+
<br>
+ if language ~= "lua" and language ~= "sql" then
<br>
+ log.error('Unknown language: %s', language)
<br>
+ os.exit(1)
<br>
+ end
<br>
+
<br>
default_cfg = d
<br>
<br>
if not usermode then
<br>
@@ -629,6 +638,12 @@ local function logrotate()
<br>
end
<br>
<br>
local function enter()
<br>
+ local options = keyword_arguments
<br>
+ language = (options.language or language):lower()
<br>
+ if language ~= "lua" and language ~= "sql" then
<br>
+ log.error('Unknown language: %s', options.language)
<br>
+ return 1
<br>
+ end
<br>
local console_sock_path = uri.parse(console_sock).service
<br>
if fio.stat(console_sock_path) == nil then
<br>
log.error("Can't connect to %s (%s)", console_sock_path,
errno.strerror())
<br>
@@ -644,7 +659,9 @@ local function enter()
<br>
console_sock, TIMEOUT_INFINITY
<br>
)
<br>
<br>
- console.on_start(function(self) self:eval(cmd) end)
<br>
+ local cmd_connect = string.format("\\set language %s",
language)
<br>
+
<br>
+ console.on_start(function(self) self:eval(cmd)
self:eval(cmd_connect) end)
<br>
console.on_client_disconnect(function(self) self.running =
false end)
<br>
console.start()
<br>
return 0
<br>
@@ -1008,11 +1025,15 @@ local commands = setmetatable({
<br>
}
<br>
}, enter = {
<br>
func = exit_wrapper(enter), process = process_local, help
= {
<br>
- header = "%s enter INSTANCE",
<br>
+ header = "%s enter INSTANCE [--language=language]",
<br>
linkmode = "%s enter",
<br>
description =
<br>
[=[
<br>
- Enter an instance's interactive Lua console.
<br>
+ Enter an instance's interactive Lua or SQL console.
<br>
+
<br>
+ Supported options:
<br>
+ * --language=language to set interactive console
language.
<br>
+ May be either Lua or SQL.
<br>
]=],
<br>
weight = 65,
<br>
deprecated = false,
<br>
@@ -1284,6 +1305,7 @@ do
<br>
{ 'chdir', 'string' },
<br>
{ 'only-server', 'string' },
<br>
{ 'server', 'string' },
<br>
+ { 'language', 'string' },
<br>
})
<br>
<br>
local cmd_name
<br>
<br>
</div>
</body>
</html>