Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
redox-os
ion
Commits
7b8f7797
Commit
7b8f7797
authored
Dec 25, 2019
by
Michal Siedlaczek
Committed by
Michael Aaron Murphy
Jan 12, 2020
Browse files
feat: Execute all commands passed from readln in interactive shell
parent
bfa4bfc5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/binary/mod.rs
View file @
7b8f7797
...
...
@@ -282,7 +282,51 @@ impl<'a> InteractiveShell<'a> {
}
}
fn
exec
<
T
:
Fn
(
&
mut
Shell
<
'_
>
)
>
(
self
,
prep_for_exit
:
&
T
)
->
!
{
fn
exec_single_command
(
&
mut
self
,
command
:
&
str
)
{
let
cmd
:
&
str
=
&
designators
::
expand_designators
(
&
self
.context
.borrow
(),
command
.trim_end
());
self
.terminated
.set
(
true
);
{
let
mut
shell
=
self
.shell
.borrow_mut
();
match
shell
.on_command
(
&
cmd
,
true
)
{
Ok
(
_
)
=>
(),
Err
(
IonError
::
PipelineExecutionError
(
PipelineError
::
CommandNotFound
(
command
)))
=>
{
if
Self
::
try_cd
(
&
command
,
&
mut
shell
)
.ok
()
.map_or
(
false
,
|
res
|
res
.is_failure
())
{
if
let
Some
(
Value
::
Function
(
func
))
=
shell
.variables
()
.get
(
"COMMAND_NOT_FOUND"
)
.cloned
()
{
if
let
Err
(
why
)
=
shell
.execute_function
(
&
func
,
&
[
"ion"
,
&
command
])
{
eprintln!
(
"ion: command not found handler: {}"
,
why
);
}
}
else
{
eprintln!
(
"ion: command not found: {}"
,
command
);
}
}
// Status::COULD_NOT_EXEC
}
Err
(
IonError
::
PipelineExecutionError
(
PipelineError
::
CommandExecError
(
ref
err
,
ref
command
,
)))
if
err
.kind
()
==
io
::
ErrorKind
::
PermissionDenied
&&
command
.len
()
==
1
=>
{
if
Self
::
try_cd
(
&
command
[
0
],
&
mut
shell
)
.ok
()
.map_or
(
false
,
|
res
|
res
.is_failure
())
{
eprintln!
(
"ion: {}"
,
err
);
shell
.reset_flow
();
}
}
Err
(
err
)
=>
{
eprintln!
(
"ion: {}"
,
err
);
shell
.reset_flow
();
}
}
}
self
.save_command
(
&
cmd
);
}
fn
exec
<
T
:
Fn
(
&
mut
Shell
<
'_
>
)
>
(
mut
self
,
prep_for_exit
:
&
T
)
->
!
{
loop
{
if
let
Err
(
err
)
=
io
::
stdout
()
.flush
()
{
eprintln!
(
"ion: failed to flush stdio: {}"
,
err
);
...
...
@@ -290,60 +334,15 @@ impl<'a> InteractiveShell<'a> {
if
let
Err
(
err
)
=
io
::
stderr
()
.flush
()
{
println!
(
"ion: failed to flush stderr: {}"
,
err
);
}
let
mut
lines
=
std
::
iter
::
from_fn
(||
self
.readln
(
prep_for_exit
))
.flat_map
(|
s
|
s
.into_bytes
()
.into_iter
()
.chain
(
Some
(
b'\n'
)));
match
Terminator
::
new
(
&
mut
lines
)
.terminate
()
{
Some
(
command
)
=>
{
let
cmd
:
&
str
=
&
designators
::
expand_designators
(
&
self
.context
.borrow
(),
command
.trim_end
(),
);
self
.terminated
.set
(
true
);
match
self
.readln
(
prep_for_exit
)
{
Some
(
lines
)
=>
{
for
command
in
lines
.into_bytes
()
.into_iter
()
.batching
(|
bytes
|
Terminator
::
new
(
bytes
)
.terminate
())
{
let
mut
shell
=
self
.shell
.borrow_mut
();
match
shell
.on_command
(
&
cmd
,
true
)
{
Ok
(
_
)
=>
(),
Err
(
IonError
::
PipelineExecutionError
(
PipelineError
::
CommandNotFound
(
command
),
))
=>
{
if
Self
::
try_cd
(
&
command
,
&
mut
shell
)
.ok
()
.map_or
(
false
,
|
res
|
res
.is_failure
())
{
if
let
Some
(
Value
::
Function
(
func
))
=
shell
.variables
()
.get
(
"COMMAND_NOT_FOUND"
)
.cloned
()
{
if
let
Err
(
why
)
=
shell
.execute_function
(
&
func
,
&
[
"ion"
,
&
command
])
{
eprintln!
(
"ion: command not found handler: {}"
,
why
);
}
}
else
{
eprintln!
(
"ion: command not found: {}"
,
command
);
}
}
// Status::COULD_NOT_EXEC
}
Err
(
IonError
::
PipelineExecutionError
(
PipelineError
::
CommandExecError
(
ref
err
,
ref
command
),
))
if
err
.kind
()
==
io
::
ErrorKind
::
PermissionDenied
&&
command
.len
()
==
1
=>
{
if
Self
::
try_cd
(
&
command
[
0
],
&
mut
shell
)
.ok
()
.map_or
(
false
,
|
res
|
res
.is_failure
())
{
eprintln!
(
"ion: {}"
,
err
);
shell
.reset_flow
();
}
}
Err
(
err
)
=>
{
eprintln!
(
"ion: {}"
,
err
);
shell
.reset_flow
();
}
}
self
.exec_single_command
(
&
command
);
}
self
.save_command
(
&
cmd
);
}
None
=>
self
.terminated
.set
(
true
),
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment