1- use std :: process :: { Output } ;
1+ use crate :: command_utils :: { run_command_by_shell , run_command_line } ;
22use crate :: errors:: KeeperError ;
3- use error_stack:: { Result } ;
43use crate :: models:: Task ;
5- use crate :: command_utils:: { run_command_by_shell, run_command_line} ;
64use crate :: task;
5+ use error_stack:: Result ;
6+ use jsonc_to_json:: jsonc_to_json;
77use serde:: { Deserialize , Serialize } ;
8+ use std:: process:: Output ;
89
910#[ derive( Serialize , Deserialize , Debug , Default ) ]
1011struct TasksJson {
@@ -27,36 +28,51 @@ pub fn is_available() -> bool {
2728}
2829
2930pub fn list_tasks ( ) -> Result < Vec < Task > , KeeperError > {
30- Ok ( parse_run_json ( ) . tasks
31+ Ok ( parse_run_json ( )
32+ . tasks
3133 . map ( |tasks| {
32- tasks. into_iter ( ) . map ( |task| {
33- if task. task_type == "shell" {
34- Some ( task ! ( & task. label. clone( ) . unwrap( ) , "vscode" , "shell" , & task. command. clone( ) . unwrap( ) ) )
35- } else if let Some ( cmd) = task. command {
36- Some ( task ! ( & task. label. clone( ) . unwrap( ) , "vscode" , & cmd) )
37- } else { None }
38- } ) . flatten ( ) . collect ( )
34+ tasks
35+ . into_iter ( )
36+ . map ( |task| {
37+ if task. task_type == "shell" {
38+ Some ( task ! (
39+ & task. label. clone( ) . unwrap( ) ,
40+ "vscode" ,
41+ "shell" ,
42+ & task. command. clone( ) . unwrap( )
43+ ) )
44+ } else if let Some ( cmd) = task. command {
45+ Some ( task ! ( & task. label. clone( ) . unwrap( ) , "vscode" , & cmd) )
46+ } else {
47+ None
48+ }
49+ } )
50+ . flatten ( )
51+ . collect ( )
3952 } )
40- . unwrap_or_else ( || vec ! [ ] )
41- )
53+ . unwrap_or_else ( || vec ! [ ] ) )
4254}
4355
44-
4556fn parse_run_json ( ) -> TasksJson {
4657 std:: env:: current_dir ( )
4758 . map ( |dir| dir. join ( ".vscode" ) . join ( "tasks.json" ) )
4859 . map ( |path| std:: fs:: read_to_string ( path) . unwrap_or ( "{}" . to_owned ( ) ) )
49- . map ( |data| serde_jsonrc:: from_str :: < TasksJson > ( & data) . expect ( ".vscode/tasks.json format" ) )
50- // ! serde_jsonrc has a bug with trailing commas inside objects (but the repo has no issues enabled). - the above fails with `Error("key must be a string", line: 123, column: 123)`
51- // Would need some investigation into the code around here: https://github.com/serde-rs/json/commit/e34885f6ec5218c721ce33b5f27eaf8bfac9649d
60+ . map ( |data| jsonc_to_json ( & data) . to_string ( ) )
61+ . map ( |data| serde_json:: from_str :: < TasksJson > ( & data) . expect ( ".vscode/tasks.json format" ) )
5262 . unwrap ( )
5363}
5464
55- pub fn run_task ( task : & str , _task_args : & [ & str ] , _global_args : & [ & str ] , verbose : bool ) -> Result < Output , KeeperError > {
65+ pub fn run_task (
66+ task : & str ,
67+ _task_args : & [ & str ] ,
68+ _global_args : & [ & str ] ,
69+ verbose : bool ,
70+ ) -> Result < Output , KeeperError > {
5671 let tasks = list_tasks ( ) ?;
57- let task = tasks. iter ( ) . find ( |t| t. name == task) . ok_or_else ( || {
58- KeeperError :: TaskNotFound ( task. to_string ( ) )
59- } ) ?;
72+ let task = tasks
73+ . iter ( )
74+ . find ( |t| t. name == task)
75+ . ok_or_else ( || KeeperError :: TaskNotFound ( task. to_string ( ) ) ) ?;
6076 if let Some ( _runner2) = & task. runner2 {
6177 run_command_by_shell ( & task. description , verbose)
6278 } else {
@@ -68,7 +84,6 @@ pub fn run_task(task: &str, _task_args: &[&str], _global_args: &[&str], verbose:
6884mod tests {
6985 use super :: * ;
7086
71-
7287 #[ test]
7388 fn test_parse ( ) {
7489 if let Ok ( tasks) = list_tasks ( ) {
0 commit comments