fn run_for_directive(
            directive: &BonesDirective,
            cmds: &HashMap<String, Bone>,
            verbose: bool,
            output: &mut impl std::io::Write,
        ) -> Result<i32, String> {
            // Get the token, which names the command we'll be running
            let command_name = &directive.0;
            // Now get the corresponding Bone if it exists
            let bone = cmds.get(command_name);
            let bone = match bone {
                Some(bone) => bone,
                None => return Err(format!("Error in executing Bones directive: subcommand '{}' not found. This is probably a typo in your Bonnie configuration.", command_name)),
            };
            // Now execute it and get the exit code (this may recursively call this function if ordered subcommands are nested, but that dcoesn't matter)
            // Bonnie treats all command cores as futures for an exit code, we don't care about any side effects (printing, server execution, etc.)
            let exit_code = bone.run(command_name, verbose, output)?;
            // Iterate over the conditions given and check if any of them match that exit code
            // We'll run the first one that does (even if more do after that)
            // TODO document the above behaviour
            let mut final_exit_code = exit_code;
            for (operator, directive) in directive.1.iter() {
                if operator.matches(&exit_code) {
                    // An operator has matched, check if it has an associated directive
                    final_exit_code = match directive {
                        // If it does, run that and get its exit code
                        Some(directive) => run_for_directive(directive, cmds, verbose, output)?,
                        // If not, return the exit code we just got above
                        None => exit_code,
                    };
                }
            }

            // All nestings have resolved to one exit code, we return it
            Ok(final_exit_code)
        }
// This system is highly recursive, so everything is done in this function for progressively less complex directives
This system is highly recursive, so everything is done in this function for progressively less complex directives
This system is highly recursive so everything is done in this function for progressively less complex directives
fn run_for_directive(
            directive: &BonesDirective,
            cmds: &HashMap<String, Bone>,
            verbose: bool,
            output: &mut impl std::io::Write,
        ) -> Result<i32, String> {
            // Get the token, which names the command we'll be running
            let command_name = &directive.0;
            // Now get the corresponding Bone if it exists
            let bone = cmds.get(command_name);
            let bone = match bone {
                Some(bone) => bone,
                None => return Err(format!("Error in executing Bones directive: subcommand '{}' not found. This is probably a typo in your Bonnie configuration.", command_name)),
            };
            // Now execute it and get the exit code (this may recursively call this function if ordered subcommands are nested, but that dcoesn't matter)
            // Bonnie treats all command cores as futures for an exit code, we don't care about any side effects (printing, server execution, etc.)
            let exit_code = bone.run(command_name, verbose, output)?;
            // Iterate over the conditions given and check if any of them match that exit code
            // We'll run the first one that does (even if more do after that)
            // TODO document the above behaviour
            let mut final_exit_code = exit_code;
            for (operator, directive) in directive.1.iter() {
                if operator.matches(&exit_code) {
                    // An operator has matched, check if it has an associated directive
                    final_exit_code = match directive {
                        // If it does, run that and get its exit code
                        Some(directive) => run_for_directive(directive, cmds, verbose, output)?,
                        // If not, return the exit code we just got above
                        None => exit_code,
                    };
                }
            }
            // All nestings have resolved to one exit code, we return it
            Ok(final_exit_code)
        }
fn run_for_directive ( directive : & BonesDirective , cmds : & HashMap < String , Bone > , verbose : bool , output : & mut impl std :: io :: Write , ) -> Result < i32 , String > { // Get the token, which names the command we'll be running let command_name = & directive . 0 ; // Now get the corresponding Bone if it exists let bone = cmds . get ( command_name ) ; let bone = match bone { Some ( bone ) => bone , None => return Err ( format ! ( " " command_name ) ) , } ; // Now execute it and get the exit code (this may recursively call this function if ordered subcommands are nested, but that dcoesn't matter) // Bonnie treats all command cores as futures for an exit code, we don't care about any side effects (printing, server execution, etc.) let exit_code = bone . run ( command_name , verbose , output ) ? ; // Iterate over the conditions given and check if any of them match that exit code // We'll run the first one that does (even if more do after that) // TODO document the above behaviour let mut final_exit_code = exit_code ; for ( operator , directive ) in directive . 1 . iter ( ) { if operator . matches ( & exit_code ) { // An operator has matched, check if it has an associated directive final_exit_code = match directive { // If it does, run that and get its exit code Some ( directive ) => run_for_directive ( directive , cmds , verbose , output ) ? , // If not, return the exit code we just got above None => exit_code , } ; } } // All nestings have resolved to one exit code, we return it Ok ( final_exit_code ) }
This system is highly recursive, so everything is done in this function for progressively less complex directives
This system is highly recursive so everything is done in this function for progressively less complex directives
directive
&BonesDirective
cmds
&HashMap<String, Bone>
verbose
bool
output
&mut impl std::io::Write