+use clap::Parser;
use std::fmt::Display;
use std::process::ExitCode;
use mastodonochrome::config::{ConfigLocation, ConfigError};
use mastodonochrome::tui::{Tui, TuiError};
+#[derive(Parser, Debug)]
+struct Args {
+ /// Directory containing configuration files.
+ #[arg(short, long)]
+ config: Option<std::path::PathBuf>,
+}
+
#[derive(Debug)]
pub struct TopLevelError {
+ prefix: String,
message: String,
}
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) ->
Result<(), std::fmt::Error>
{
- write!(f, "mastodonochrome: error: {}", self.message)
+ write!(f, "mastodonochrome: {}{}", self.prefix, self.message)
}
}
-trait TopLevelErrorCandidate: Display {}
+trait TopLevelErrorCandidate: Display {
+ fn get_prefix() -> String { "error: ".to_owned() }
+}
impl<E: TopLevelErrorCandidate> From<E> for TopLevelError {
fn from(err: E) -> Self {
TopLevelError {
+ prefix: E::get_prefix(),
message: err.to_string(),
}
}
impl TopLevelErrorCandidate for ConfigError {}
impl TopLevelErrorCandidate for TuiError {}
+impl TopLevelErrorCandidate for clap::error::Error {
+ // clap prints its own "error: "
+ fn get_prefix() -> String { "".to_owned() }
+}
fn main_inner() -> Result<(), TopLevelError> {
- let cfgloc = ConfigLocation::default()?;
+ let cli = Args::try_parse()?;
+ let cfgloc = match cli.config {
+ None => ConfigLocation::default()?,
+ Some(dir) => ConfigLocation::from_pathbuf(dir),
+ };
Tui::run(&cfgloc)?;
Ok(())
}