Skip to content

Commit

Permalink
refactor: get rid of the anyhow crate
Browse files Browse the repository at this point in the history
Fixes #89
  • Loading branch information
quite authored and b1rger committed Sep 16, 2024
1 parent 0f08bdf commit 4b3403f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ keywords = ["calendar", "ical", "cli", "date", "cal"]
categories = ["command-line-utilities", "date-and-time"]

[dependencies]
anyhow = "1.0"
chrono = { version = "0.4", default-features = false, features = ["clock"] }
clap = { version = "4.4.18", features = ["derive", "cargo"] }
toml = "0.8.*"
Expand Down
15 changes: 7 additions & 8 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: MIT

use anyhow::{anyhow, Result};
use chrono::prelude::*;
use clap::{crate_authors, crate_name, crate_version, Args, Parser};

Expand Down Expand Up @@ -66,7 +65,7 @@ pub struct Action {
}

impl Cli {
pub fn validate_date(&self) -> Result<chrono::NaiveDate> {
pub fn validate_date(&self) -> Result<chrono::NaiveDate, String> {
let mut today: chrono::NaiveDate = Local::now().date_naive();
let mut year: i32 = today.year();
let mut month: u32 = today.month();
Expand All @@ -76,7 +75,7 @@ impl Cli {
year = match self.date[0].parse() {
Ok(x) => {
if x > 9999 {
return Err(anyhow!(
return Err(format!(
"{}: illegal year value: use 1-9999: {}",
crate_name!(),
x
Expand All @@ -85,7 +84,7 @@ impl Cli {
x
}
Err(x) => {
return Err(anyhow!(
return Err(format!(
"{}: illegal year value: use 1-9999: {}",
crate_name!(),
x
Expand All @@ -97,7 +96,7 @@ impl Cli {
month = match self.date[1].parse() {
Ok(x) => {
if x > 12 {
return Err(anyhow!(
return Err(format!(
"{}: illegal month value: use 1-12: {}",
crate_name!(),
x
Expand All @@ -106,7 +105,7 @@ impl Cli {
x
}
Err(x) => {
return Err(anyhow!(
return Err(format!(
"{}: illegal month value: use 1-12: {}",
crate_name!(),
x
Expand All @@ -119,7 +118,7 @@ impl Cli {
day = match self.date[2].parse() {
Ok(x) => {
if x > 31 {
return Err(anyhow!(
return Err(format!(
"{}: illegal day value: use 1-12: {}",
crate_name!(),
x
Expand All @@ -128,7 +127,7 @@ impl Cli {
x
}
Err(x) => {
return Err(anyhow!(
return Err(format!(
"{}: illegal day value: use 1-12: {}",
crate_name!(),
x
Expand Down
3 changes: 1 addition & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use crate::cli::{Action, Cli};
use crate::config::StyleType;
use crate::config::{Config, Theme};
use crate::events::EventInstances;
use anyhow::Result;
use chrono::prelude::*;
use clap::Parser;

Expand All @@ -21,7 +20,7 @@ pub struct Context {
}

impl Context {
pub fn new() -> Result<Context> {
pub fn new() -> Result<Context, String> {
let mut opts: Cli = Cli::parse();
let config: Config = Config::read();
let theme: Theme = if opts.theme.is_some() {
Expand Down

0 comments on commit 4b3403f

Please sign in to comment.