fix or silence most warnings
This commit is contained in:
parent
12501c8c73
commit
8bc7405d63
46
src/main.rs
46
src/main.rs
|
@ -30,6 +30,8 @@ future improvements:
|
|||
- search ADJ_TIMEYWIMEY to find places that need adjusting if the bot might run late
|
||||
(that's an incomplete list, but tag things as you notice them…)
|
||||
*/
|
||||
#![allow(dead_code)] // ≈100 warnings for yet-to-be-used stuff…
|
||||
#![allow(unused_macros)]
|
||||
|
||||
use chrono::{Datelike, Local, NaiveDate, Weekday};
|
||||
use clap::{Arg, Command};
|
||||
|
@ -38,6 +40,8 @@ use regex::Regex;
|
|||
use std::borrow::Cow;
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fmt::Display;
|
||||
use std::io::IsTerminal;
|
||||
|
||||
mod key_value;
|
||||
use key_value::KeyValueStore as KV;
|
||||
|
@ -235,6 +239,9 @@ fn parse_args() -> Args {
|
|||
/* ***** Main ***** */
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
if std::io::stdout().is_terminal() {
|
||||
println!(include_str!("chaosknoten.txt"), VERSION = env!("CARGO_PKG_VERSION"));
|
||||
}
|
||||
// set up config file access
|
||||
let args = parse_args();
|
||||
trace_var!(args);
|
||||
|
@ -242,8 +249,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
verboseln!("Using config file {}.", config_file.cyan());
|
||||
let config = KV::new(config_file).unwrap();
|
||||
config_spec::populate_defaults(&CONFIG_SPEC, &config);
|
||||
// select mode
|
||||
if args.check_mode {
|
||||
println!(include_str!("chaosknoten.txt"), VERSION = env!("CARGO_PKG_VERSION"));
|
||||
return config_spec::interactive_check(&CONFIG_SPEC, config);
|
||||
}
|
||||
// get config
|
||||
|
@ -280,7 +287,8 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
let mut last_state = ProgramState::parse(&config["state-name"]);
|
||||
let last_run = config.get("state-last-run").unwrap_or_default();
|
||||
let last_run = NaiveDate::parse_from_str(&last_run, "%Y-%m-%d").unwrap_or_default();
|
||||
// figure out where we should be
|
||||
trace_var!(last_run);
|
||||
// reset state if this hasn't been run for too long
|
||||
if (today - last_run).num_days() > 10 {
|
||||
if !matches!(last_state, ProgramState::Normal) {
|
||||
eprintln!("WARNING: last run was a long time ago, resetting state.");
|
||||
|
@ -289,6 +297,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
}
|
||||
let last_state = last_state;
|
||||
// figure out where we should be
|
||||
// deltas has either 2 or 3 days, if 3 then the middle one is == 0 (i.e. today)
|
||||
let deltas: Vec<i64> = nearest_plenum_days.iter().map(|&d| (d - today).num_days()).collect();
|
||||
// find the relevant one:
|
||||
|
@ -327,7 +336,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
verboseln!("Soll-Zustand: {}", intended_state.to_string().cyan());
|
||||
|
||||
let action: &ST = &TRANSITION_LUT[last_state as usize][intended_state as usize];
|
||||
trace_var!(action);
|
||||
verboseln!("Notewendige Aktionen: {}", action.to_string().cyan());
|
||||
action.get()(delta, &plenum_day, &config, &hedgedoc, &email, &wiki)?;
|
||||
|
||||
// TODO: cleanup / write new state
|
||||
|
@ -338,6 +347,14 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
return Ok(());
|
||||
}
|
||||
|
||||
/* ** dead code beyond this point ** */
|
||||
|
||||
let _ = (); // dummy line so linter doesn't highlight the entire following block
|
||||
|
||||
#[allow(unused_variables)]
|
||||
#[rustfmt::skip]
|
||||
{
|
||||
|
||||
// Dienstage diesen Monat
|
||||
let all_tuesdays: Vec<NaiveDate> = get_all_weekdays(0, Weekday::Tue);
|
||||
let zweiter_dienstag: String = all_tuesdays[1].to_string(); // z.B. 2024-07-09
|
||||
|
@ -506,6 +523,8 @@ Und hier ist das Protokoll des letzten Plenums:
|
|||
"matrix-password",
|
||||
])
|
||||
.ok();
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_all_weekdays(month_offset: i32, week_day: Weekday) -> Vec<NaiveDate> {
|
||||
|
@ -573,7 +592,7 @@ fn generate_new_pad_for_following_date(
|
|||
übernächster_plenumtermin,
|
||||
überübernächster_plenumtermin,
|
||||
)
|
||||
.unwrap_or_else(|error| template_content); // Try regex, if not successful use without regex
|
||||
.unwrap_or(template_content); // Try regex, if not successful use without regex
|
||||
|
||||
match hedgedoc.import_note(Some(&pad_id), template_modified) {
|
||||
Ok(_) => {
|
||||
|
@ -652,6 +671,7 @@ fn upper_first(s: &str) -> String {
|
|||
|
||||
// BBBBBBBBBB
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn do_announcement(
|
||||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
|
@ -660,6 +680,7 @@ fn do_announcement(
|
|||
todo!()
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn do_reminder(
|
||||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
|
@ -668,6 +689,7 @@ fn do_reminder(
|
|||
todo!()
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
fn do_protocol(
|
||||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
|
@ -678,6 +700,7 @@ fn do_protocol(
|
|||
|
||||
/// General cleanup function. Call as `(999, today, …)` for a complete reset
|
||||
/// based on today as the base date.
|
||||
#[allow(unused_variables)]
|
||||
fn do_cleanup(
|
||||
ttp: i64, plenum_day: &NaiveDate, config: &KV, hedgedoc: &HedgeDoc, email: &SimpleEmail,
|
||||
wiki: &Mediawiki,
|
||||
|
@ -732,6 +755,12 @@ impl ST {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for ST {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
fn nop(
|
||||
_: i64, _: &NaiveDate, _: &KV, _: &HedgeDoc, _: &SimpleEmail, _: &Mediawiki,
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
|
@ -816,14 +845,7 @@ impl ProgramState {
|
|||
|
||||
impl std::fmt::Display for ProgramState {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let str = match self {
|
||||
ProgramState::Normal => "Normal",
|
||||
ProgramState::Announced => "Announced",
|
||||
ProgramState::Reminded => "Reminded",
|
||||
ProgramState::Waiting => "Waiting",
|
||||
ProgramState::Logged => "Logged",
|
||||
};
|
||||
write!(f, "{}", str)
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue