colored std-output for better readability
This commit is contained in:
		
							parent
							
								
									c4fc33bc50
								
							
						
					
					
						commit
						81714dfdc0
					
				
					 4 changed files with 26 additions and 9 deletions
				
			
		|  | @ -1,5 +1,6 @@ | |||
| use std::error::Error; | ||||
| 
 | ||||
| use colored::Colorize; | ||||
| use lettre::{Message, SmtpTransport, Transport}; | ||||
| use lettre::message::{header, SinglePart}; | ||||
| use lettre::transport::smtp::authentication::Credentials; | ||||
|  | @ -104,8 +105,9 @@ impl Email { | |||
|             Ok(message_id) | ||||
|         } else { | ||||
|             println!( | ||||
|                 "[DRY RUN - NOT sending email]\n(raw message:)\n{}", | ||||
|                 std::str::from_utf8(&email.formatted()).unwrap_or("((UTF-8 error))") | ||||
|                 "{}\n(raw message:)\n{}", | ||||
|                 "[DRY RUN - NOT sending email]".yellow(), | ||||
|                 std::str::from_utf8(&email.formatted()).unwrap_or("((UTF-8 error))").blue() | ||||
|             ); | ||||
|             Ok("dummy-message-id@localhost".to_string()) | ||||
|         } | ||||
|  |  | |||
|  | @ -16,11 +16,13 @@ | |||
| //! let all_ok = !cfg.has_errors();
 | ||||
| //! ```
 | ||||
| 
 | ||||
| use rusqlite::{params, Connection, Result}; | ||||
| use std::cell::Cell; | ||||
| use std::collections::HashSet; | ||||
| use std::ops::Index; | ||||
| 
 | ||||
| use colored::Colorize; | ||||
| use rusqlite::{Connection, params, Result}; | ||||
| 
 | ||||
| /// Simple SQLite-backed key/value store.
 | ||||
| ///
 | ||||
| /// All failing writes will log a message, any errors will set `has_errors`.
 | ||||
|  | @ -122,10 +124,10 @@ impl KeyValueStore { | |||
|         while let Some(row) = rows.next()? { | ||||
|             let key: String = row.get(0)?; | ||||
|             if exclude_set.contains(key.as_str()) { | ||||
|                 eprintln!("{} = REDACTED", key); | ||||
|                 eprintln!("{}{}", key, " = REDACTED".blue()); | ||||
|             } else { | ||||
|                 let value: String = row.get(1)?; | ||||
|                 eprintln!("{} = {}", key, value); | ||||
|                 eprintln!("{}{}{}", key, " = ".blue(), value.blue()); | ||||
|             } | ||||
|         } | ||||
|         Ok(()) | ||||
|  |  | |||
							
								
								
									
										19
									
								
								src/main.rs
									
										
									
									
									
								
							
							
						
						
									
										19
									
								
								src/main.rs
									
										
									
									
									
								
							|  | @ -4,6 +4,7 @@ use std::error::Error; | |||
| 
 | ||||
| use chrono::{Datelike, Local, NaiveDate, Weekday}; | ||||
| use clap::{Arg, Command}; | ||||
| use colored::Colorize; | ||||
| use regex::Regex; | ||||
| use reqwest::blocking::Client; | ||||
| 
 | ||||
|  | @ -133,6 +134,19 @@ fn parse_args() -> Args { | |||
| 
 | ||||
| fn main() -> Result<(), Box<dyn Error>> { | ||||
|     // set up config file access
 | ||||
| 
 | ||||
|     let ansi_art = r#" | ||||
|    _____ _____ _____ ____    _____  _                            ____        _   
 | ||||
|   / ____/ ____/ ____|  _ \  |  __ \| |                          |  _ \      | |  
 | ||||
|  | |   | |   | |    | |_) | | |__) | | ___ _ __  _   _ _ __ ___ | |_) | ___ | |_ 
 | ||||
|  | |   | |   | |    |  _ <  |  ___/| |/ _ \ '_ \| | | | '_ ` _ \|  _ < / _ \| __| | ||||
|  | |___| |___| |____| |_) | | |    | |  __/ | | | |_| | | | | | | |_) | (_) | |_ 
 | ||||
|   \_____\_____\_____|____/  |_|    |_|\___|_| |_|\__,_|_| |_| |_|____/ \___/ \__| | ||||
| 
 | ||||
| "#;
 | ||||
| 
 | ||||
|     println!("{}", ansi_art.red()); | ||||
|     
 | ||||
|     let args = parse_args(); | ||||
|     let config_file = args.config_file.as_str(); | ||||
|     let config = KV::new(config_file).unwrap(); | ||||
|  | @ -154,7 +168,7 @@ fn main() -> Result<(), Box<dyn Error>> { | |||
|         &config["email-to"], | ||||
|         config.get("email-in-reply-to").ok(), | ||||
|     ); | ||||
|     println!("[START]\nAktueller Zustand der DB:"); | ||||
|     println!("[START]\n{}", "Aktueller Zustand der DB:".bold()); | ||||
|     config.dump_redacting(&["email-password", "wiki-http-password", "wiki-api-secret", "matrix-password"]).ok(); | ||||
| 
 | ||||
|     // Dienstage diesen Monat
 | ||||
|  | @ -332,8 +346,7 @@ Und hier ist das Protokoll des letzten Plenums: | |||
|         mediawiki::pad_ins_wiki(old_pad_content_without_top_instructions); | ||||
|     } | ||||
|     println!("message id: {:?}", message_id); | ||||
| 
 | ||||
|     println!("[ENDE]\nAktueller Zustand der DB:"); | ||||
|     println!("[ENDE]\n{}", "Aktueller Zustand der DB:".bold()); | ||||
|     config.dump_redacting(&["email-password", "wiki-http-password", "wiki-api-secret", "matrix-password"]).ok(); | ||||
| 
 | ||||
|     if config.has_errors() { | ||||
|  |  | |||
|  | @ -3,7 +3,6 @@ use std::fs::File; | |||
| use std::io::Read; | ||||
| 
 | ||||
| use pandoc::{PandocError, PandocOutput}; | ||||
| use reqwest; | ||||
| use reqwest::blocking::Client; | ||||
| use serde::Deserialize; | ||||
| 
 | ||||
|  | @ -105,3 +104,4 @@ pub fn get_login_token(client: &Client, http_user: &str, http_pass: &String) -> | |||
|     let response_deserialized: QueryResponse = serde_json::from_str(&resp)?; | ||||
|     Ok(response_deserialized.query.tokens.logintoken) | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 murmeldin
							murmeldin