/// Reads a line, parses it as a command and attempts to execute it.
Reads a line, parses it as a command and attempts to execute it.
Reads a line parses it as a command and attempts to execute it .
pub fn run<MCUF: Flash, EXTF: Flash, R: image::Reader, WUS: WriteUpdateSignal>(
        &mut self,
        boot_manager: &mut BootManager<MCUF, EXTF, SRL, R, WUS>,
        greeting: &'static str,
    ) {
        if !self.greeted {
            uprintln!(self.serial, "");
            uprintln!(self.serial, "{}", greeting);
            uprintln!(self.serial, "Type `help` for a list of commands");
            self.greeted = true;
        }
        if self.needs_prompt {
            uprint!(self.serial, "{}", PROMPT);
            self.needs_prompt = false;
        }
        let mut execute_command = || -> Result<(), Error> {
            let mut buffer = [0u8; BUFFER_SIZE];
            block!(self.read_line(&mut buffer))?;
            let text = from_utf8(&buffer).map_err(|_| Error::BadCommandEncoding)?;
            let (name, arguments) = Self::parse(text)?;
            commands::run(self, boot_manager, name, arguments)?;
            Ok(())
        };
        match execute_command() {
            Err(Error::BadCommandEncoding) => {
                uwriteln!(self.serial, "[CLI Error] Bad command encoding")
            }
            Err(Error::CharactersNotAllowed) => {
                uwriteln!(self.serial, "[CLI Error] Illegal characters in command")
            }
            Err(Error::MalformedArguments) => {
                uwriteln!(self.serial, "[CLI Error] Malformed command arguments")
            }
            Err(Error::SerialBufferOverflow) => {
                uwriteln!(self.serial, "[CLI Error] Command string too long")
            }
            Err(Error::MissingArgument) => {
                uwriteln!(self.serial, "[CLI Error] Command missing an argument")
            }
            Err(Error::DuplicateArguments) => {
                uwriteln!(self.serial, "[CLI Error] Command contains duplicate arguments")
            }
            Err(Error::ApplicationError(e)) => {
                uwriteln!(self.serial, "[CLI Error] Internal boot manager error: ").ok().unwrap();
                e.report(&mut self.serial);
                Ok(())
            }
            Err(Error::UnexpectedArguments) => {
                uwriteln!(self.serial, "[CLI Error] Command contains an unexpected argument")
            }
            Err(Error::ArgumentOutOfRange) => {
                uwriteln!(self.serial, "[CLI Error] Argument is out of valid range")
            }
            Err(Error::SerialReadError) => uwriteln!(self.serial, "[CLI Error] Serial read failed"),
            Err(Error::CommandUnknown) => uwriteln!(self.serial, "Unknown command"),
            Err(Error::CommandEmpty) => Ok(()),
            Ok(_) => Ok(()),
        }
        .ok()
        .unwrap();
        self.needs_prompt = true;
    }
pub fn run < MCUF : Flash , EXTF : Flash , R : image :: Reader , WUS : WriteUpdateSignal > ( & mut self , boot_manager : & mut BootManager < MCUF , EXTF , SRL , R , WUS > , greeting : & ' static str , ) { if ! self . greeted { uprintln ! ( self serial " " ) ; uprintln ! ( self serial " " greeting ) ; uprintln ! ( self serial " " ) ; self . greeted = true ; } if self . needs_prompt { uprint ! ( self serial " " PROMPT ) ; self . needs_prompt = false ; } let mut execute_command = | | -> Result < ( ) , Error > { let mut buffer = [ 0u8 ; BUFFER_SIZE ] ; block ! ( self read_line ( mut buffer ) ) ? ; let text = from_utf8 ( & buffer ) . map_err ( | _ | Error :: BadCommandEncoding ) ? ; let ( name , arguments ) = Self :: parse ( text ) ? ; commands :: run ( self , boot_manager , name , arguments ) ? ; Ok ( ( ) ) } ; match execute_command ( ) { Err ( Error :: BadCommandEncoding ) => { uwriteln ! ( self serial " " ) } Err ( Error :: CharactersNotAllowed ) => { uwriteln ! ( self serial " " ) } Err ( Error :: MalformedArguments ) => { uwriteln ! ( self serial " " ) } Err ( Error :: SerialBufferOverflow ) => { uwriteln ! ( self serial " " ) } Err ( Error :: MissingArgument ) => { uwriteln ! ( self serial " " ) } Err ( Error :: DuplicateArguments ) => { uwriteln ! ( self serial " " ) } Err ( Error :: ApplicationError ( e ) ) => { uwriteln ! ( self serial " " ) . ok ( ) . unwrap ( ) ; e . report ( & mut self . serial ) ; Ok ( ( ) ) } Err ( Error :: UnexpectedArguments ) => { uwriteln ! ( self serial " " ) } Err ( Error :: ArgumentOutOfRange ) => { uwriteln ! ( self serial " " ) } Err ( Error :: SerialReadError ) => uwriteln ! ( self serial " " ) , Err ( Error :: CommandUnknown ) => uwriteln ! ( self serial " " ) , Err ( Error :: CommandEmpty ) => Ok ( ( ) ) , Ok ( _ ) => Ok ( ( ) ) , } . ok ( ) . unwrap ( ) ; self . needs_prompt = true ; }
Reads a line, parses it as a command and attempts to execute it.
Reads a line parses it as a command and attempts to execute it .
&mut self
boot_manager
&mut BootManager<MCUF, EXTF, SRL, R, WUS>
greeting
&'static str