pub fn new_cli(args: &cli::args::Args) -> Result<Info> {
        let block = match Block::from_dev(&args.device) {
            Ok(block) => Some(block),
            Err(Error::InvalidArg(_)) => None,
            Err(e) => return Err(e.into()),
        };
        Ok(Info {
            path: args.device.clone(),
            block_size: BlockSize::new(match args.block {
                Some(s) => s,
                None => {
                    // Needed because `block_size` can be None for Restore,
                    // and clap will ensure that it's provided if `override_block`
                    // is passed.
                    //
                    // Example cmd: `cargo run -- /tmp/disk2.img restore < /tmp/test`
                    // Which MUST work correctly.
                    //
                    // For other commands we want the default auto behavior.
                    if let Some(cli::args::Commands::Restore { .. }) = args.cmd {
                        0
                    } else {
                        block
                            .as_ref() //
                            .ok_or_else(|| {
                                anyhow!("Couldn't automatically determine logical block size")
                            })?
                            .logical_block_size()?
                    }
                }
            }),
            disk_size: Size::from_bytes(match block.as_ref() {
                Some(block) => block.size()?,
                None => fs::metadata(&args.device)?.len(),
            }),
            model: match block.as_ref() {
                Some(block) => block.model()?.unwrap_or_default(),
                None => String::new(),
            },
            name: args
                .device
                .file_stem()
                .ok_or_else(|| anyhow!("Invalid device file"))?
                .to_str()
                .ok_or_else(|| anyhow!("Invalid UTF-8 in device file name"))?
                .to_owned(),
        })
    }
/// Get information on a device from CLI args
Get information on a device from CLI args
Get information on a device from CLI args
pub fn new_cli(args: &cli::args::Args) -> Result<Info> {
        let block = match Block::from_dev(&args.device) {
            Ok(block) => Some(block),
            Err(Error::InvalidArg(_)) => None,
            Err(e) => return Err(e.into()),
        };
        Ok(Info {
            path: args.device.clone(),
            block_size: BlockSize::new(match args.block {
                Some(s) => s,
                None => {
                    // Needed because `block_size` can be None for Restore,
                    // and clap will ensure that it's provided if `override_block`
                    // is passed.
                    //
                    // Example cmd: `cargo run -- /tmp/disk2.img restore < /tmp/test`
                    // Which MUST work correctly.
                    //
                    // For other commands we want the default auto behavior.
                    if let Some(cli::args::Commands::Restore { .. }) = args.cmd {
                        0
                    } else {
                        block
                            .as_ref() //
                            .ok_or_else(|| {
                                anyhow!("Couldn't automatically determine logical block size")
                            })?
                            .logical_block_size()?
                    }
                }
            }),
            disk_size: Size::from_bytes(match block.as_ref() {
                Some(block) => block.size()?,
                None => fs::metadata(&args.device)?.len(),
            }),
            model: match block.as_ref() {
                Some(block) => block.model()?.unwrap_or_default(),
                None => String::new(),
            },
            name: args
                .device
                .file_stem()
                .ok_or_else(|| anyhow!("Invalid device file"))?
                .to_str()
                .ok_or_else(|| anyhow!("Invalid UTF-8 in device file name"))?
                .to_owned(),
        })
    }
pub fn new_cli ( args : & cli :: args :: Args ) -> Result < Info > { let block = match Block :: from_dev ( & args . device ) { Ok ( block ) => Some ( block ) , Err ( Error :: InvalidArg ( _ ) ) => None , Err ( e ) => return Err ( e . into ( ) ) , } ; Ok ( Info { path : args . device . clone ( ) , block_size : BlockSize :: new ( match args . block { Some ( s ) => s , None => { // Needed because `block_size` can be None for Restore, // and clap will ensure that it's provided if `override_block` // is passed. // // Example cmd: `cargo run -- /tmp/disk2.img restore < /tmp/test` // Which MUST work correctly. // // For other commands we want the default auto behavior. if let Some ( cli :: args :: Commands :: Restore { .. } ) = args . cmd { 0 } else { block . as_ref ( ) // . ok_or_else ( | | { anyhow ! ( " " ) } ) ? . logical_block_size ( ) ? } } } ) , disk_size : Size :: from_bytes ( match block . as_ref ( ) { Some ( block ) => block . size ( ) ? , None => fs :: metadata ( & args . device ) ? . len ( ) , } ) , model : match block . as_ref ( ) { Some ( block ) => block . model ( ) ? . unwrap_or_default ( ) , None => String :: new ( ) , } , name : args . device . file_stem ( ) . ok_or_else ( | | anyhow ! ( " " ) ) ? . to_str ( ) . ok_or_else ( | | anyhow ! ( " " ) ) ? . to_owned ( ) , } ) }
Get information on a device from CLI args
Get information on a device from CLI args
args
&cli::args::Args
args
&cli::args::Args