Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
picodata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
core
picodata
Commits
7fbb0d01
Commit
7fbb0d01
authored
5 months ago
by
Вартан Бабаян
Browse files
Options
Downloads
Patches
Plain Diff
fix: add EOF when process input from files
parent
0bf5381c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1390
add EOF as second delimiter along with ;
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/cli/console.rs
+38
-20
38 additions, 20 deletions
src/cli/console.rs
test/int/test_cli_ux.py
+8
-6
8 additions, 6 deletions
test/int/test_cli_ux.py
with
46 additions
and
26 deletions
src/cli/console.rs
+
38
−
20
View file @
7fbb0d01
use
nix
::
unistd
::
isatty
;
use
std
::
collections
::
VecDeque
;
use
std
::
env
;
use
std
::
fs
::
read_to_string
;
...
...
@@ -69,6 +70,7 @@ pub struct Console<H: Helper> {
// Queue of separated by delimiter statements
separated_statements
:
VecDeque
<
String
>
,
uncompleted_statement
:
String
,
eof_received
:
bool
,
}
impl
<
T
:
Helper
>
Console
<
T
>
{
...
...
@@ -79,14 +81,14 @@ impl<T: Helper> Console<T> {
fn
handle_special_command
(
&
mut
self
,
command
:
&
str
)
->
Result
<
ControlFlow
<
Command
>>
{
match
command
{
"
\\
e"
=>
self
.open_external_editor
(),
"
\\
help"
|
"
\\
h"
=>
Ok
(
ControlFlow
::
Break
(
Command
::
Control
(
"
\\
e"
|
"
\\
e;"
=>
self
.open_external_editor
(),
"
\\
help"
|
"
\\
h"
|
"
\\
help;"
|
"
\\
h;"
=>
Ok
(
ControlFlow
::
Break
(
Command
::
Control
(
SpecialCommand
::
PrintHelp
,
))),
"
\\
lua"
=>
Ok
(
ControlFlow
::
Break
(
Command
::
Control
(
"
\\
lua"
|
"
\\
lua;"
=>
Ok
(
ControlFlow
::
Break
(
Command
::
Control
(
SpecialCommand
::
SwitchLanguageToLua
,
))),
"
\\
sql"
=>
Ok
(
ControlFlow
::
Break
(
Command
::
Control
(
"
\\
sql"
|
"
\\
sql;"
=>
Ok
(
ControlFlow
::
Break
(
Command
::
Control
(
SpecialCommand
::
SwitchLanguageToSql
,
))),
_
=>
self
.handle_parsed_command
(
command
),
...
...
@@ -190,8 +192,27 @@ impl<T: Helper> Console<T> {
Ok
(
Some
(
command
))
}
fn
process_command
(
&
mut
self
)
{
if
let
Some
(
ref
delimiter
)
=
self
.delimiter
{
while
let
Some
((
separated_part
,
tail
))
=
self
.uncompleted_statement
.split_once
(
delimiter
)
{
self
.separated_statements
.push_back
(
separated_part
.into
());
self
.uncompleted_statement
=
tail
.into
();
}
}
else
{
self
.separated_statements
.push_back
(
std
::
mem
::
take
(
&
mut
self
.uncompleted_statement
));
}
}
pub
fn
read
(
&
mut
self
)
->
Result
<
Option
<
Command
>>
{
loop
{
if
self
.eof_received
{
self
.write
(
"Bye"
);
return
Ok
(
None
);
}
while
let
Some
(
separated_input
)
=
self
.separated_statements
.pop_front
()
{
let
processed
=
{
if
separated_input
.starts_with
(
Self
::
SPECIAL_COMMAND_PREFIX
)
{
...
...
@@ -217,10 +238,7 @@ impl<T: Helper> Console<T> {
match
readline
{
Ok
(
line
)
=>
{
if
line
.is_empty
()
{
return
Ok
(
Some
(
Command
::
Expression
(
line
)));
}
// process special command with no need for delimiter
if
line
.starts_with
(
Self
::
SPECIAL_COMMAND_PREFIX
)
{
let
processed
=
self
.handle_special_command
(
&
line
)
?
;
...
...
@@ -230,24 +248,22 @@ impl<T: Helper> Console<T> {
}
}
else
{
self
.uncompleted_statement
+=
&
line
;
if
let
Some
(
ref
delimiter
)
=
self
.delimiter
{
while
let
Some
((
separated_part
,
tail
))
=
self
.uncompleted_statement
.split_once
(
delimiter
)
{
self
.separated_statements
.push_back
(
separated_part
.into
());
self
.uncompleted_statement
=
tail
.into
();
}
}
else
{
self
.separated_statements
.push_back
(
std
::
mem
::
take
(
&
mut
self
.uncompleted_statement
));
}
self
.process_command
();
}
}
Err
(
ReadlineError
::
Interrupted
)
=>
{
self
.write
(
"CTRL+C"
);
}
Err
(
ReadlineError
::
Eof
)
=>
{
let
is_terminal
=
isatty
(
0
)
.unwrap_or
(
false
);
if
!
is_terminal
&&
!
self
.uncompleted_statement
.is_empty
()
{
self
.eof_received
=
true
;
return
Ok
(
Some
(
Command
::
Expression
(
std
::
mem
::
take
(
&
mut
self
.uncompleted_statement
,
))));
}
self
.write
(
"Bye"
);
return
Ok
(
None
);
}
...
...
@@ -304,6 +320,7 @@ impl Console<LuaHelper> {
delimiter
:
Some
(
DELIMITER
.to_string
()),
separated_statements
:
VecDeque
::
new
(),
uncompleted_statement
:
String
::
new
(),
eof_received
:
false
,
})
}
}
...
...
@@ -318,6 +335,7 @@ impl Console<()> {
delimiter
:
Some
(
DELIMITER
.to_string
()),
separated_statements
:
VecDeque
::
new
(),
uncompleted_statement
:
String
::
new
(),
eof_received
:
false
,
})
}
}
This diff is collapsed.
Click to expand it.
test/int/test_cli_ux.py
+
8
−
6
View file @
7fbb0d01
...
...
@@ -34,14 +34,14 @@ def test_connect_ux(cluster: Cluster):
cli
.
expect_exact
(
"
picodata>
"
)
# sql console doesn't know about language switching
cli
.
sendline
(
"
\\
lua
"
)
cli
.
sendline
(
"
\\
lua
;
"
)
cli
.
expect_exact
(
"
Unknown special sequence
"
)
cli
.
sendline
(
"
\\
sql
"
)
cli
.
expect_exact
(
"
Unknown special sequence
"
)
# for not registried command nothing can happen
cli
.
sendline
(
"
\\
lya
"
)
cli
.
sendline
(
"
\\
lya
;
"
)
cli
.
expect_exact
(
"
Unknown special sequence
"
)
cli
.
sendline
(
"
\\
scl
"
)
cli
.
expect_exact
(
"
Unknown special sequence
"
)
...
...
@@ -114,7 +114,7 @@ def test_admin_ux(cluster: Cluster):
cli
.
sendline
(
"
\\
lua
"
)
cli
.
expect_exact
(
"
Language switched to Lua
"
)
cli
.
sendline
(
"
\\
sql
"
)
cli
.
sendline
(
"
\\
sql
;
"
)
cli
.
expect_exact
(
"
Language switched to SQL
"
)
# for not registried command nothing happend
...
...
@@ -133,7 +133,7 @@ def test_admin_ux(cluster: Cluster):
cli
.
expect_exact
(
"
Language switched to SQL
"
)
# nothing happens on completion in SQL mode
cli
.
sendline
(
"
\\
sql
"
)
cli
.
sendline
(
"
\\
sql
;
"
)
cli
.
expect_exact
(
"
Language switched to SQL
"
)
cli
.
sendline
(
"
\t\t
"
)
cli
.
expect_exact
(
"
picodata>
"
)
...
...
@@ -431,9 +431,11 @@ def test_cat_file_to_picodata_admin_stdin(cluster: Cluster):
CREATE TABLE ids (id INTEGER NOT NULL, PRIMARY KEY(id))
USING MEMTX
DISTRIBUTED BY (id);
INSERT INTO ids
VALUES(1);
SELECT * FROM ids;
SELECT * FROM ids
"""
,
)
...
...
@@ -462,7 +464,7 @@ def test_cat_file_to_picodata_connect_stdin(cluster: Cluster):
[
cluster
.
binary_path
,
"
admin
"
,
f
"
{
i1
.
data_dir
}
/admin.sock
"
],
input
=
b
"""
\
CREATE USER
"
alice
"
WITH PASSWORD
'
T0psecret
'
;
GRANT CREATE TABLE TO
"
alice
"
;
GRANT CREATE TABLE TO
"
alice
"
"""
,
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment