@@ -106,6 +106,8 @@ fn print_err(msg: &str, lineno: usize) {
106
106
eprintln ! ( "Invalid command: {} on line {}" , msg, lineno)
107
107
}
108
108
109
+ /// Get a list of commands from a file. Does the work of ensuring the commands
110
+ /// are syntactically valid.
109
111
fn get_commands ( template : & str ) -> Result < Vec < Command > , ( ) > {
110
112
let mut commands = Vec :: new ( ) ;
111
113
let mut errors = false ;
@@ -147,10 +149,7 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
147
149
}
148
150
}
149
151
150
- let args = match cap. name ( "args" ) {
151
- Some ( m) => shlex:: split ( m. as_str ( ) ) . unwrap ( ) ,
152
- None => vec ! [ ] ,
153
- } ;
152
+ let args = cap. name ( "args" ) . map_or ( vec ! [ ] , |m| shlex:: split ( m. as_str ( ) ) . unwrap ( ) ) ;
154
153
155
154
if !cmd. validate ( & args, commands. len ( ) , lineno) {
156
155
errors = true ;
@@ -163,15 +162,14 @@ fn get_commands(template: &str) -> Result<Vec<Command>, ()> {
163
162
if !errors { Ok ( commands) } else { Err ( ( ) ) }
164
163
}
165
164
165
+ /// Performs the actual work of ensuring a command passes. Generally assumes the command
166
+ /// is syntactically valid.
166
167
fn check_command ( command : Command , cache : & mut Cache ) -> Result < ( ) , CkError > {
167
168
let result = match command. kind {
168
169
CommandKind :: Has => {
169
170
match command. args . len ( ) {
170
171
// @has <path> = file existence
171
- 1 => match cache. get_file ( & command. args [ 0 ] ) {
172
- Ok ( _) => true ,
173
- Err ( _) => false ,
174
- } ,
172
+ 1 => cache. get_file ( & command. args [ 0 ] ) . is_ok ( ) ,
175
173
// @has <path> <jsonpath> = check path exists
176
174
2 => {
177
175
let val = cache. get_value ( & command. args [ 0 ] ) ?;
0 commit comments