Skip to content

Commit

Permalink
Merge pull request #5 from fleetingbytes/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
fleetingbytes authored Feb 15, 2025
2 parents e7850d2 + a4fa8e0 commit 02741e5
Show file tree
Hide file tree
Showing 11 changed files with 864 additions and 305 deletions.
652 changes: 499 additions & 153 deletions Cargo.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ categories = ["command-line-utilities"]
[workspace]

[dependencies]
chrono = "0.4.34"
clap = { version = "4.5", features = ["derive"] }
clap_complete = "4.5"
clap_complete_nushell = "4.5"
color-eyre = "0.6.2"
confy = { version = "0.6.0", features = ["ron_conf"], default-features = false }
directories = "5.0.1"
serde = { version = "1.0.196", features = ["derive"] }
sqlite = "0.33.0"
tracing = "0.1.40"
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "env-filter", "registry"] }
two_timer = "2.2.5"
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,25 @@ We regularly cook meals from a small repertoir of recipes. Yet, when deciding wh
* `mrot add spaghetti` records that you've had spaghetti today
* `mrot add pizza --date yesterday` records that you've had a pizza yesterday
* `mrot add steak --date 2024-02-10` records that you've had a steak on February 10 2024
* `mrot add carp --date "tomorrow" --date "day after tomorrow"` records that you plan to have carp tomorrow and on the day after tomorrow

* `mrot what` will show you some meals which you haven't had for the longest time
* `mrot what --number 5` will show you five meals which you haven't had for the longest time
* `mrot what --ignore liver --ignore salad` will show you will show you some meals which you haven't had for the longest time, ignoring liver and salad

* `mrot plan add "lamb chops" "next Sunday"` will plan lamb chops for the next Sunday
* `mrot plan show` will show the next planned meals according to the configuration
* `mrot plan show --number 4` will show the next four planned meals
* `mrot plan show --days 3` will show the planned meals for the next 3 days
* `mrot plan remove meal "tomato soup"` will remove any tomato soups planned in the future
* `mrot plan remove date "next Thursday"` will remove any planned meals on the next Thursday
* `mrot plan remove until "2024-03-01"` will remove any planned meals from today until March 1st 2024
* `mrot show` will show the past and next planned meals according to the configuration
* `mrot show "from last Tuesday to next Monday"` will show the recorded or planned meals in the given time range
* `mrot show "this week"` will show the past and future meals in this week
* `mrot when "spaghetti"` will show the past and future dates where spaghetti were recorded
* `mrot remove "from last week to next week"` will remove all meals in the specified time range
* `mrot remove "from last month to the end of this month" --meal "tomato soup"` will remove the specified meal in the specified time range

* `mrot random` will show you one random meal from your past or planned meals

* `mrot config set what number 5` will configure mrot to suggest three oldest meals (default: 3)
* `mrot config set plan number 2` will configure mrot to show up to two planned meals (default: 3)
* `mrot config set plan days 7` will configure mrot to show the planned meals up to 7 days in the future (default: 5)
* `mrot config set show "from the day before yesterday until tomorrow"` will configure mrot to show the meals planned for the specified range
* `mrot config get what number` will show how many meals is mrot configured to suggest
* `mrot config get plan number` will show how many planned meals is mrot configured to show
* `mrot config get plan days` will show how many days of planned meals is mrot configured to show
* `mrot config get show` will show the time in which mrot-show will show meals
* `mrot config ignore add liver` will add liver to the ignore list
* `mrot config ignore remove salad` will remove salad from the ignore list
* `mrot config ignore show` will list the ignored meals
Expand Down
8 changes: 8 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::env::{self, VarError};

fn main() -> Result<(), VarError> {
let pkg_name = env::var("CARGO_PKG_NAME")?;
let pkg_name_uppercase = pkg_name.to_uppercase();
println!("cargo:rustc-env=PKG_NAME_UPPERCASE={}", pkg_name_uppercase);
Ok(())
}
47 changes: 44 additions & 3 deletions src/bin/mrot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,50 @@
#![deny(missing_docs)]

use color_eyre::eyre::Report;
use mrot::cli::translate_cli_to_api;
use directories::ProjectDirs;
use mrot::error::Error;
use tracing::error;
use tracing_appender::non_blocking;
use tracing_subscriber::{filter::EnvFilter, fmt, fmt::format::FmtSpan, prelude::*};

const LOG_FILE: &str = "trace.log";
const PKG_NAME: &str = env!("CARGO_PKG_NAME");
const LOG_LEVEL_ENV_VAR: &str = concat!(env!("PKG_NAME_UPPERCASE"), "_LOG_LEVEL");

fn init_tracing() -> Result<Vec<impl Drop>, Error> {
let (non_blocking_stderr, stderr_guard) = non_blocking(std::io::stderr());
let stderr_log_layer = fmt::layer()
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE)
.with_writer(non_blocking_stderr)
.without_time()
.pretty();

let dirs =
ProjectDirs::from("", "", PKG_NAME).ok_or(Error::NoDirectory("ProjectDirs".to_string()))?;
let log_file = dirs.data_dir().join(LOG_FILE);
let log_file_writer = std::fs::File::create(log_file)?;
let (non_blocking_file, file_guard) = non_blocking(log_file_writer);
let file_log_layer = fmt::layer()
.with_writer(non_blocking_file)
.with_span_events(FmtSpan::NEW | FmtSpan::CLOSE);

tracing_subscriber::registry()
.with(stderr_log_layer.with_filter(EnvFilter::from_env(LOG_LEVEL_ENV_VAR)))
.with(file_log_layer)
.init();

Ok(vec![stderr_guard, file_guard])
}

fn main() -> Result<(), Report> {
translate_cli_to_api()?;
Ok(())
color_eyre::install()?;
let _guards = init_tracing()?;
match mrot::cli::run() {
Ok(_) => Ok(()),
Err(e) if matches!(e, Error::TimeSpanNotSupported) => {
error!("{}", e);
Err(Report::new(e))
}
Err(e) => Err(Report::new(e)),
}
}
Loading

0 comments on commit 02741e5

Please sign in to comment.