@@ -76,34 +76,13 @@ fn read_config_inner(manifest_path: &Path) -> Result<Config> {
76
76
config. test_success_exit_code = Some ( exit_code as i32 ) ;
77
77
}
78
78
( "run-command" , Value :: Array ( array) ) => {
79
- let mut command = Vec :: new ( ) ;
80
- for value in array {
81
- match value {
82
- Value :: String ( s) => command. push ( s) ,
83
- _ => return Err ( anyhow ! ( "run-command must be a list of strings" ) ) ,
84
- }
85
- }
86
- config. run_command = Some ( command) ;
79
+ config. run_command = Some ( parse_string_array ( array, "run-command" ) ?) ;
87
80
}
88
81
( "run-args" , Value :: Array ( array) ) => {
89
- let mut args = Vec :: new ( ) ;
90
- for value in array {
91
- match value {
92
- Value :: String ( s) => args. push ( s) ,
93
- _ => return Err ( anyhow ! ( "run-args must be a list of strings" ) ) ,
94
- }
95
- }
96
- config. run_args = Some ( args) ;
82
+ config. run_args = Some ( parse_string_array ( array, "run-args" ) ?) ;
97
83
}
98
84
( "test-args" , Value :: Array ( array) ) => {
99
- let mut args = Vec :: new ( ) ;
100
- for value in array {
101
- match value {
102
- Value :: String ( s) => args. push ( s) ,
103
- _ => return Err ( anyhow ! ( "test-args must be a list of strings" ) ) ,
104
- }
105
- }
106
- config. test_args = Some ( args) ;
85
+ config. test_args = Some ( parse_string_array ( array, "test-args" ) ?) ;
107
86
}
108
87
( key, value) => {
109
88
return Err ( anyhow ! (
@@ -118,6 +97,17 @@ fn read_config_inner(manifest_path: &Path) -> Result<Config> {
118
97
Ok ( config. into ( ) )
119
98
}
120
99
100
+ fn parse_string_array ( array : Vec < Value > , prop_name : & str ) -> Result < Vec < String > > {
101
+ let mut parsed = Vec :: new ( ) ;
102
+ for value in array {
103
+ match value {
104
+ Value :: String ( s) => parsed. push ( s) ,
105
+ _ => return Err ( anyhow ! ( "{} must be a list of strings" , prop_name) ) ,
106
+ }
107
+ }
108
+ Ok ( parsed)
109
+ }
110
+
121
111
#[ derive( Default ) ]
122
112
struct ConfigBuilder {
123
113
run_command : Option < Vec < String > > ,
0 commit comments