<commit_before>// Copyright (C) 2015, <NAME> <<EMAIL>>
// All rights reserved. This file is part of rpf, distributed under the
// BSD 3-Clause license. For full terms please see the LICENSE file.

use utils::PathMod;
use utils::Styled;
use utils::Color;

use std::process;
use std::path::PathBuf;

/// Enum used for setting exit statuses
#[derive(Copy,Clone)]
pub enum Status {
    Ok,
    Error,
    OptError,
    ArgError,
}

impl Status {
    /// Wrapper for `process::exit`, immediately exits the process with the set
    /// exit status.
    ///
    /// # Example
    ///
    /// ```should_panic
    /// use rpf::Status;
    ///
    /// Status::ArgError.exit();
    /// ```
    pub fn exit(self) {
        process::exit(self as i32);
    }

    /// Used for errors, prints error messages in red terminal font and calls
    /// `rpf::exit`
    ///
    /// # Example
    ///
    /// ```should_panic
    /// use rpf::Status;
    /// use std::path::Path;
    ///
    /// let file = Path::new("file.txt");
    /// Status::Error.err("util", "Hit an error".to_string());
    /// ```
    pub fn err(&self, rpf: &str, mesg: String) {
        println!("{}{} {}", rpf.paint(Color::Red), ":".paint(Color::Red),
        mesg.paint(Color::Red));
        self.exit();
    }

    /// Used for errors when working with paths, works similar to `err`
    pub fn path_err(&self, mesg: String, item: PathBuf) {
        println!("{}{} {}", item.as_str().paint(Color::Red),
        ":".paint(Color::Red), mesg.paint(Color::Red));
        self.exit();
    }

}
<commit_msg>status: set `Status` as `Exit` trait for `Prog`<commit_after>// Copyright (C) 2015, <NAME> <<EMAIL>>
// All rights reserved. This file is part of rpf, distributed under the
// BSD 3-Clause license. For full terms please see the LICENSE file.

use utils::PathMod;
use utils::Styled;
use utils::Color;

use std::process;
use std::path::PathBuf;

use utils::Prog;

/// Enum used for setting exit statuses
#[derive(Copy,Clone)]
pub enum ExitStatus {
    Ok,
    Error,
    OptError,
    ArgError,
}

pub trait Exit {
    /// Wrapper for `process::exit`, immediately exits the process with the set
    /// exit status.
    ///
    /// # Example
    // Ignored here as doc-tests are ended because of `std::process::exit`
    /// ```ignore
    /// use rpf::{Prog,Exit,ExitStatus};
    ///
    /// let prog = Prog { name: "test", vers: "0.1.0", yr: "2015" };
    /// prog.exit(ExitStatus::Ok);
    /// ```
    fn exit(&self, status: ExitStatus);

    /// Used for errors, prints error messages in red terminal font and calls
    /// `rpf::Exit::exit`
    ///
    /// # Example
    // Ignored here as doc-tests are ended because of `std::process::exit`
    /// ```ignore
    /// use rpf::{Prog,Exit,ExitStatus};
    ///
    /// let prog = Prog { name: "test", vers: "0.1.0", yr: "2015" };
    /// prog.error("Some kind of error occured!".to_string(), ExitStatus::Error);
    /// ```
    fn error(&self, mesg: String, status: ExitStatus);

    /// Used for errors when working with paths, works similar to `error`
    fn path_error(&self, mesg: String, item: PathBuf);
}

impl Exit for Prog {
    fn exit(&self, status: ExitStatus) {
        process::exit(status as i32);
    }

    fn error(&self, mesg: String, status: ExitStatus) {
        println!("{}{} {}", self.name.paint(Color::Red), ":".paint(Color::Red),
        mesg.paint(Color::Red));
        &self.exit(status);
    }

     fn path_error(&self, mesg: String, item: PathBuf) {
        println!("{}{} {}", item.as_str().paint(Color::Red),
        ":".paint(Color::Red), mesg.paint(Color::Red));
        &self.exit(ExitStatus::Error);
    }
}

{'fraction_non_alphanumeric': 0.18640350877192982, 'fraction_numerical': 0.007675438596491228, 'mean_word_length': 2.522200772200772, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7444895', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1200, 'n_words': 340}