Skip to content

Commit

Permalink
refactor: major refactoring of the code base
Browse files Browse the repository at this point in the history
`opts` was renamed to `cli` to conform to upstreams (clap) naming
convention

`lib` was renamed to `utils`

The whole style module was split up - the styles as defined in the theme
are now part of the theme module. The `utils` module contains a simple
method to convert the style definition from the theme to a string.

`theme` is now a submodule of `config`

The `DateProperty` is now part of the theme as well.

The `date`, `calendar` and `agenda` modules where moved to a new
`output` module.
  • Loading branch information
b1rger committed Jul 28, 2023
1 parent c94d129 commit 19726c2
Show file tree
Hide file tree
Showing 16 changed files with 415 additions and 435 deletions.
34 changes: 17 additions & 17 deletions src/opts.rs → src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//
// SPDX-License-Identifier: MIT

use crate::lib::types::ChronoDate;
use crate::utils::ChronoDate;
use anyhow::{anyhow, Result};
use chrono::prelude::*;
use clap::{crate_authors, crate_name, crate_version, Parser};

#[derive(Parser)]
#[clap(version = crate_version!(), author = crate_authors!(","), about = "Display a calendar")]
pub struct Opts {
pub struct Cli {
#[clap(short = '1', long = "one", help = "show only current month (default)", conflicts_with_all = &["three", "year"])]
pub one: bool,
#[clap(
Expand Down Expand Up @@ -39,9 +39,9 @@ pub struct Opts {
pub date: Vec<String>,
}

impl Default for Opts {
impl Default for Cli {
fn default() -> Self {
Opts {
Cli {
one: true,
three: false,
year: false,
Expand All @@ -56,7 +56,7 @@ impl Default for Opts {
}
}

impl Opts {
impl Cli {
pub fn validate_date(&self) -> Result<ChronoDate> {
let mut today: ChronoDate = Local::now().date_naive();
let mut year: i32 = today.year();
Expand Down Expand Up @@ -148,13 +148,13 @@ mod tests {
#[test]
fn test_validate_date_defaults_to_now() {
let today: ChronoDate = Local::now().date_naive();
let o: Opts = Opts::default();
let o: Cli = Cli::default();
assert_eq!(today, o.validate_date().unwrap());
}
#[test]
fn test_validate_date_default_to_now_with_custom_year() {
let today: ChronoDate = Local::now().date_naive().with_year(2007).unwrap();
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![String::from("2007")];
assert_eq!(today, o.validate_date().unwrap());
}
Expand All @@ -166,7 +166,7 @@ mod tests {
.unwrap()
.with_month(1)
.unwrap();
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![String::from("2007"), String::from("1")];
assert_eq!(today, o.validate_date().unwrap());
}
Expand All @@ -180,14 +180,14 @@ mod tests {
.unwrap()
.with_day(28)
.unwrap();
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![String::from("2007"), String::from("1"), String::from("28")];
assert_eq!(today, o.validate_date().unwrap());
}
#[test]
fn test_validate_date_defaults_to_now_with_ambiguous_arguments() {
let today: ChronoDate = Local::now().date_naive();
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![
String::from("2007"),
String::from("1"),
Expand All @@ -198,19 +198,19 @@ mod tests {
}
#[test]
fn test_validate_date_errors_with_wrong_month() {
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![String::from("2007"), String::from("13"), String::from("28")];
assert!(o.validate_date().is_err());
}
#[test]
fn test_validate_date_errors_with_wrong_day() {
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![String::from("2007"), String::from("11"), String::from("33")];
assert!(o.validate_date().is_err());
}
#[test]
fn test_validate_date_errors_with_wrong_year() {
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![
String::from("999999"),
String::from("11"),
Expand All @@ -220,13 +220,13 @@ mod tests {
}
#[test]
fn test_validate_date_errors_with_unparsable_year() {
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![String::from("foo"), String::from("13"), String::from("28")];
assert!(o.validate_date().is_err());
}
#[test]
fn test_validate_date_errors_with_unparsable_month() {
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![
String::from("2007"),
String::from("foo"),
Expand All @@ -236,7 +236,7 @@ mod tests {
}
#[test]
fn test_validate_date_errors_with_unparsable_day() {
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![
String::from("2007"),
String::from("11"),
Expand All @@ -247,7 +247,7 @@ mod tests {
#[test]
fn test_validate_date_errors_with_non_existent_date() {
let today: ChronoDate = Local::now().date_naive();
let mut o: Opts = Opts::default();
let mut o: Cli = Cli::default();
o.date = vec![String::from("2007"), String::from("2"), String::from("30")];
assert_eq!(today, o.validate_date().unwrap());
}
Expand Down
261 changes: 0 additions & 261 deletions src/config/carlstyle.rs

This file was deleted.

Loading

0 comments on commit 19726c2

Please sign in to comment.