pash 0.3.0

Simple and easy app for generating and storing passwords
Documentation
//! View files' content

use super::edit::FileContent;
use anyhow::{Context, Result};
use std::io::Read;

/// View methods
pub struct View;

impl View {
    /// Get passwords.toml content and print out
    pub fn view_all() -> Result<()> {
        let mut password_file = {
            FileContent::default()
                .context("Failed to open files")?
                .password_file
        };
        let mut password_string = String::new();
        password_file
            .read_to_string(&mut password_string)
            .context("Failed to write 'passwords.toml' content to string")?;
        let password_split = password_string.split('\n');
        let password_vector: Vec<String> = password_split.map(|s| s.to_string()).collect();
        for line in password_vector {
            println!("{}", line.as_str());
        }
        Ok(())
    }
    /// Get all matches from passwords.toml using pattern and print out
    pub fn view_password(pattern: String) -> Result<()> {
        let mut password_file = {
            FileContent::default()
                .context("Failed to open files")?
                .password_file
        };
        let mut password_string = String::new();
        password_file
            .read_to_string(&mut password_string)
            .context("Failed to write 'passwords.toml' content to string")?;
        let password_split = password_string.split('\n');
        let password_vector: Vec<String> = password_split.map(|s| s.to_string()).collect();
        for line in password_vector {
            if line.contains(pattern.as_str())
                && !(line
                    .chars()
                    .nth(0)
                    .context("Failed to get first character of line")?
                    == '[')
            {
                println!("{}", line.as_str())
            }
        }

        Ok(())
    }
}