@@ -5,17 +5,17 @@ use std::rc::Rc;
55use anyhow:: Context ;
66use clap:: Parser ;
77use deno_task_shell:: parser:: debug_parse;
8- use deno_task_shell:: {
9- execute_sequential_list, AsyncCommandBehavior , ExecuteResult , ShellCommand , ShellPipeReader ,
10- ShellPipeWriter , ShellState ,
11- } ;
8+ use deno_task_shell:: { ShellCommand , ShellState } ;
129use rustyline:: error:: ReadlineError ;
1310use rustyline:: { CompletionType , Config , Editor } ;
1411
1512mod commands;
1613mod completion;
14+ mod execute;
1715mod helper;
1816
17+ pub use execute:: execute;
18+
1919fn commands ( ) -> HashMap < String , Rc < dyn ShellCommand > > {
2020 HashMap :: from ( [
2121 (
@@ -30,43 +30,13 @@ fn commands() -> HashMap<String, Rc<dyn ShellCommand>> {
3030 "unalias" . to_string ( ) ,
3131 Rc :: new ( commands:: AliasCommand ) as Rc < dyn ShellCommand > ,
3232 ) ,
33+ (
34+ "source" . to_string ( ) ,
35+ Rc :: new ( commands:: SourceCommand ) as Rc < dyn ShellCommand > ,
36+ ) ,
3337 ] )
3438}
3539
36- async fn execute ( text : & str , state : & mut ShellState ) -> anyhow:: Result < i32 > {
37- let list = deno_task_shell:: parser:: parse ( text) ;
38-
39- let mut stderr = ShellPipeWriter :: stderr ( ) ;
40- let stdout = ShellPipeWriter :: stdout ( ) ;
41- let stdin = ShellPipeReader :: stdin ( ) ;
42-
43- if let Err ( e) = list {
44- let _ = stderr. write_line ( & format ! ( "Syntax error: {}" , e) ) ;
45- return Ok ( 1 ) ;
46- }
47-
48- // spawn a sequential list and pipe its output to the environment
49- let result = execute_sequential_list (
50- list. unwrap ( ) ,
51- state. clone ( ) ,
52- stdin,
53- stdout,
54- stderr,
55- AsyncCommandBehavior :: Wait ,
56- )
57- . await ;
58-
59- match result {
60- ExecuteResult :: Continue ( exit_code, changes, _) => {
61- // set CWD to the last command's CWD
62- state. apply_changes ( & changes) ;
63- std:: env:: set_current_dir ( state. cwd ( ) ) . context ( "Failed to set CWD" ) ?;
64- Ok ( exit_code)
65- }
66- ExecuteResult :: Exit ( _, _) => Ok ( 0 ) ,
67- }
68- }
69-
7040#[ derive( Parser ) ]
7141struct Options {
7242 /// The path to the file that should be executed
@@ -93,10 +63,6 @@ async fn interactive() -> anyhow::Result<()> {
9363 let helper = helper:: ShellPromptHelper :: default ( ) ;
9464 rl. set_helper ( Some ( helper) ) ;
9565
96- // let h = ShellCompleter {};
97-
98- // rl.set_helper(Some(h));
99-
10066 let mut state = init_state ( ) ;
10167
10268 let home = dirs:: home_dir ( ) . context ( "Couldn't get home directory" ) ?;
0 commit comments