Skip to content

Commit

Permalink
feat: implement -n, --months <num>
Browse files Browse the repository at this point in the history
  • Loading branch information
quite authored and b1rger committed Sep 14, 2024
1 parent ad60895 commit 0bf5887
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ cargo install carl

- **-1**, **--one**: Display single month output. (This is the default.)
- **-3**, **--three**: Display prev/current/next month output.
- **-n**, **--months NUMBER**: Display current and following months.
- **-s**, **--sunday**: Display Sunday as the first day of the week.
- **-m**, **--monday**: Display Monday as the first day of the week.
- **-j**, **--julian**: Display Julian dates (days one-based, numbered from January 1).
- **-y**, **--year**: Display a calendar for the current year.
- **-V**, **--version**: Display version information and exit.
- **-h**, **--help**: Display help screen and exit.
- **--theme**: Set the theme that should be used
- **--themestyletype**: "dark" or "light", use the theme styles marked for "dark" or for "light" backgrounds. Defaults to "light"
- **--theme THEME**: Set the theme that should be used
- **--themestyletype TYPE**: "dark" or "light", use the theme styles marked for "dark" or for "light" backgrounds. Defaults to "light"
- **-a**, **--agenda**: Display agenda (a listing of all the events that occur in the the displayed calendar timespan) below the calendar

## Commandline options
Expand Down
11 changes: 8 additions & 3 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,21 @@ use clap::{crate_authors, crate_name, crate_version, Args, Parser};
#[derive(Parser)]
#[clap(version = crate_version!(), author = crate_authors!(","), about = "Display a calendar")]
pub struct Cli {
#[clap(short = '1', long = "one", help = "show only current month (default)", conflicts_with_all = &["three", "year"])]
#[clap(short = '1', long = "one", help = "show only current month (default)", conflicts_with_all = &["three", "year", "months"])]
pub one: bool,
#[clap(
short = '3',
long = "three",
help = "show previous, current and next month",
conflicts_with_all = &["one", "year"]
conflicts_with_all = &["one", "year", "months"]
)]
pub three: bool,
#[clap(short = 'y', long = "year", help = "show whole current year", conflicts_with_all = &["one", "three"])]
#[clap(short = 'n', long = "months",
value_name="NUMBER", value_parser = clap::value_parser!(u8).range(1..),
help = "show current and following months, in total NUMBER months",
conflicts_with_all = &["one", "three", "year"])]
pub months: Option<u8>,
#[clap(short = 'y', long = "year", help = "show whole current year", conflicts_with_all = &["one", "three", "months"])]
pub year: bool,
#[clap(short = 's', long = "sunday", help = "Sunday as first day of week")]
pub sunday: bool,
Expand Down
13 changes: 12 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ fn main() {
months.push(daterangeend);
columns = 3;
}
if let Some(num) = ctx.opts.months {
daterangebegin = ctx.usersetdate.first_day_of_month();
let mut tmpdate = daterangebegin;
months.push(tmpdate);
for _ in 1..=(num - 1) {
tmpdate = tmpdate.first_day_of_next_month();
months.push(tmpdate);
}
daterangeend = tmpdate.last_day_of_month();
columns = 3;
}
if ctx.opts.year {
daterangebegin = ctx.usersetdate.first_day_of_year();
daterangeend = ctx.usersetdate.last_day_of_year();
Expand All @@ -66,7 +77,7 @@ fn main() {
}
columns = 3;
}
if !ctx.opts.three && !ctx.opts.year {
if !ctx.opts.three && !ctx.opts.year && ctx.opts.months.is_none() {
months.push(ctx.usersetdate);
}

Expand Down

0 comments on commit 0bf5887

Please sign in to comment.