File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 1+ use crate :: built_in:: Action ;
2+ use std:: process:: Command ;
3+
4+ pub fn eval ( arguments : Vec < & str > ) -> Action {
5+ if arguments. len ( ) < 1 {
6+ panic ! ( "eval expects **one or more** arguments" ) ;
7+ }
8+
9+ let output = Command :: new ( arguments[ 0 ] ) . args ( & arguments[ 1 ..] ) . spawn ( ) ;
10+ match output {
11+ Ok ( mut output) => {
12+ output. wait ( ) . expect ( "failed to wait for process exit" ) ;
13+ }
14+ Err ( err) => println ! ( "{:?}" , err)
15+ }
16+ Action :: Nothing
17+ }
Original file line number Diff line number Diff line change 11mod cd;
22mod exit;
3+ mod eval;
34
45#[ derive( Debug ) ]
56pub enum Action {
67 Exit ,
78 ChangeDirectory ( String ) ,
9+ Nothing
810}
911
1012fn get_function ( command : String ) -> Option < fn ( Vec < & str > ) -> Action > {
1113 let registry = [
1214 ( "exit" , exit:: exit as fn ( Vec < & str > ) -> Action ) ,
1315 ( "cd" , cd:: cd as fn ( Vec < & str > ) -> Action ) ,
16+ ( "eval" , eval:: eval as fn ( Vec < & str > ) -> Action )
1417 ] ;
1518 let mut function: Option < fn ( Vec < & str > ) -> Action > = None ;
1619
You can’t perform that action at this time.
0 commit comments