~deadjakk/RiceStats

b061158d554d08123a4cc30e28b26b94a1bb3bfc — deadjakk 2 years ago 5662400
updated to make update bin more flexible
2 files changed, 17 insertions(+), 4 deletions(-)

M src/main.rs
M src/updates_utils.rs
M src/main.rs => src/main.rs +2 -2
@@ 1,6 1,6 @@
mod updates_utils;
mod network;
use updates_utils::apt_updates;
use updates_utils::get_updates;
use network::usage;
use structopt::StructOpt;



@@ 41,7 41,7 @@ fn main() {
    }

    if args.apt == true {
        if let Err(e) = apt_updates(&mut output_line){
        if let Err(e) = get_updates(&mut output_line){
            eprintln!("Error received attempting show_updates: {}",e);
        }
    }

M src/updates_utils.rs => src/updates_utils.rs +15 -2
@@ 2,7 2,7 @@ use rice_stats::{RiceError,run_command};
use sudo::{check,RunningAs,escalate_if_needed};
use regex::Regex;

pub fn apt_updates(output_line: &mut String) -> Result<(),RiceError> {
pub fn get_updates(output_line: &mut String) -> Result<(),RiceError> {
    match check() {
        RunningAs::User => {
            return Err(RiceError::SUIDFailed);


@@ 15,11 15,24 @@ pub fn apt_updates(output_line: &mut String) -> Result<(),RiceError> {
        return Err(RiceError::SUIDFailed);
    }

    // check if apt is available (ubuntu/debian)
    match run_command("which apt",&mut "".to_string()) {
        Ok(_) => {
            if let Err(_) = apt_poll(output_line){
            }
            return Ok(());
        }
        Err(_) => (),
    }
    Ok(())
}

fn apt_poll (output_line: &mut String) -> Result<(),RiceError> {
    let mut command_to_parse = String::new();
    if let Err(_) = run_command("apt update -y", &mut command_to_parse){
        eprintln!("erroneous error output: {}",command_to_parse);
    }
    

    let pattern = Regex::new("\\d+? packages").unwrap();
    let p_match = pattern.captures(&command_to_parse);
    match p_match {