Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of the anyhow crate #139

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading