diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2021-04-06 20:40:44 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2021-04-06 20:40:44 +0200 |
| commit | fc85f34301a99e404433650f3f4cd4d4ed24ec3b (patch) | |
| tree | ae48cbb217202a77f09410a3003d9756bad79983 | |
| parent | b555f2105f7e2e8c402e995205e214d46ab24686 (diff) | |
| download | mum-fc85f34301a99e404433650f3f4cd4d4ed24ec3b.tar.gz | |
remove anyhow
| -rw-r--r-- | Cargo.lock | 7 | ||||
| -rw-r--r-- | mumctl/Cargo.toml | 1 | ||||
| -rw-r--r-- | mumctl/src/main.rs | 41 |
3 files changed, 29 insertions, 20 deletions
@@ -32,12 +32,6 @@ dependencies = [ ] [[package]] -name = "anyhow" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28b2cd92db5cbd74e8e5028f7e27dd7aa3090e89e4f2a197cc7c8dfb69c7063b" - -[[package]] name = "arrayref" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -849,7 +843,6 @@ dependencies = [ name = "mumctl" version = "0.3.0" dependencies = [ - "anyhow", "bincode", "colored", "log", diff --git a/mumctl/Cargo.toml b/mumctl/Cargo.toml index 0da7fa4..621b1d0 100644 --- a/mumctl/Cargo.toml +++ b/mumctl/Cargo.toml @@ -13,7 +13,6 @@ license = "MIT" [dependencies] mumlib = { version = "0.3", path = "../mumlib" } -anyhow = "1" bincode = "1" colored = "2" log = "0.4" diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 4ce8016..0314cab 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -1,15 +1,9 @@ -use anyhow::Result; use colored::Colorize; use log::*; use mumlib::command::{Command as MumCommand, CommandResponse}; use mumlib::config::{self, Config, ServerConfig}; use mumlib::state::Channel as MumChannel; -use std::{ - fmt::Formatter, - io::{self, BufRead, Read, Write}, - iter, - os::unix::net::UnixStream, -}; +use std::{fmt,io::{self, BufRead, Read, Write}, iter, os::unix::net::UnixStream}; use structopt::{clap::Shell, StructOpt}; const INDENTATION: &str = " "; @@ -153,10 +147,28 @@ enum CliError { NoServers, } +#[derive(Debug)] +struct Error(Box<dyn std::error::Error>); // new type since otherwise we'd get an impl conflict with impl<T> From<T> for T below + +impl<E> From<E> for Error +where + E: std::error::Error + fmt::Display + 'static, +{ + fn from(e: E) -> Self { + Error(Box::new(e)) + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + std::fmt::Display::fmt(&self.0, f) + } +} + impl std::error::Error for CliError {} -impl std::fmt::Display for CliError { - fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { +impl fmt::Display for CliError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { CliError::NoUsername => { write!(f, "No username specified") @@ -168,7 +180,7 @@ impl std::fmt::Display for CliError { write!(f, "Server '{}' not found", s) } CliError::NotSet(s) => { - write!(f, "Key '{}' not set", s) //TODO + write!(f, "Key '{}' not set", s) } CliError::UseServerRename => { write!(f, "Use 'server rename' instead") @@ -186,10 +198,15 @@ impl std::fmt::Display for CliError { } } -fn main() -> Result<()> { +fn main() { log::set_logger(&LOGGER) .map(|()| log::set_max_level(LevelFilter::Info)) .unwrap(); + if let Err(e) = match_opt() { + error!("{}", e); + } +} +fn match_opt() -> Result<(), Error> { let mut config = config::read_default_cfg()?; let opt = Mum::from_args(); @@ -346,7 +363,7 @@ fn main() -> Result<()> { Ok(()) } -fn match_server_command(server_command: Server, config: &mut Config) -> Result<()> { +fn match_server_command(server_command: Server, config: &mut Config) -> Result<(), CliError> { match server_command { Server::Config { server_name, |
