Skip to content

Commit

Permalink
Fix CLI option name overlaps
Browse files Browse the repository at this point in the history
Previously, there was an overlap in the naming of the Shortforms of some
CLI options, resulting in some weird and unintuitive Error Messages.
  • Loading branch information
isiko committed Jul 3, 2024
1 parent b213a0c commit 2dabb57
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 34 deletions.
18 changes: 9 additions & 9 deletions cli-client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ This Project aims to creat a simple to use Commandline application that interfac
* [x] name <name>
* [x] budget <budget>
* [x] comment <comment>
* [ ] meals
* [ ] meals
* [x] add <recipe_ref> <servings> <calories> <start_time> <end_time> [<comment>] [<location_ref>]
* [ ] remove <reciepe_ref> [<start_time>]
* [ ] edit <reciepe_ref> [<start_time>]
* [ ] recipe <recipe_ref>
* [ ] location <location_ref>
* [ ] servings <servings>
* [ ] calories <calories>
* [ ] start <start_time>
* [ ] end <end_time>
* [ ] comment <comment>
* [ ] edit <meal_id>
* [ ] [--recipe <recipe_ref>]
* [ ] [--location <location_ref>]
* [ ] [--servings <servings>]
* [ ] [--calories <calories>]
* [ ] [--start <start_time>]
* [ ] [--end <end_time>]
* [ ] [--comment <comment>]
* [x] shopping
* [x] add
* [x] tour <date> <store>
Expand Down
18 changes: 9 additions & 9 deletions cli-client/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,10 @@ pub struct EditEventMealsAddCommand {
pub calories: i32,

/// Start time of the meal
pub start_time: String,
pub start_time: NaiveDateTime,

/// End time of the meal
pub end_time: String,
pub end_time: NaiveDateTime,

/// Location for giving out the meal
pub location: i32,
Expand All @@ -747,31 +747,31 @@ pub struct EditEventMealsEditCommand {
/// Meal ID
pub meal_id: i32,

#[clap(long, short)]
#[clap(long = "recipe", short = 'r')]
/// New recipe of the meal
pub new_recipe: Option<String>,

#[clap(long, short)]
#[clap(long = "location", short = 'l')]
/// New location of the meal
pub new_location: Option<String>,

#[clap(long, short)]
#[clap(long = "servings", short = 's')]
/// New servings of the meal
pub new_servings: Option<i32>,

#[clap(long, short)]
#[clap(long = "energy", short = 'e')]
/// New calories of the meal
pub new_calories: Option<i32>,

#[clap(long, short)]
#[clap(long = "start")]
/// New start time of the meal
pub new_start_time: Option<String>,

#[clap(long, short)]
#[clap(long = "end")]
/// New end time of the meal
pub new_end_time: Option<String>,

#[clap(long, short)]
#[clap(long = "comment")]
/// New comment of the meal
pub new_comment: Option<String>,
}
Expand Down
41 changes: 25 additions & 16 deletions cli-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ async fn main() {
.get_event_from_string_reference(_event_ref.to_string())
.await;

let event_id = if let Some(event) = event_id {
let event = if let Some(event) = event_id {
event
} else {
println!("Event not found");
Expand All @@ -1158,7 +1158,7 @@ async fn main() {
EditEventType::Name(name) => {
let event = Event {
event_name: name.name.clone(),
..event_id
..event
};
let query = food_base.update_event(&event).await;
match query {
Expand Down Expand Up @@ -1186,7 +1186,7 @@ async fn main() {
};
let event = Event {
budget: budget.clone(),
..event_id
..event
};

let query = food_base.update_event(&event).await;
Expand All @@ -1207,7 +1207,7 @@ async fn main() {
EditEventType::Comment(comment) => {
let event = Event {
comment: comment.comment.clone(),
..event_id
..event
};
let query = food_base.update_event(&event).await;
match query {
Expand Down Expand Up @@ -1240,18 +1240,16 @@ async fn main() {

let servings = meal.servings;
let calories = meal.calories;
let start_time = meal.start_time.as_str();
let end_time = meal.end_time.as_str();
let start_time = dateparser::parse(start_time).unwrap();
let end_time = dateparser::parse(end_time).unwrap();
let start_time = meal.start_time;
let end_time = meal.end_time;
let place_id = meal.location;

let query = food_base.add_meal(
event_id.event_id,
event.event_id,
recipe.recipe_id,
place_id,
start_time.naive_local(),
end_time.naive_local(),
start_time,
end_time,
calories.into(),
servings,
meal.comment.clone(),
Expand Down Expand Up @@ -1281,14 +1279,25 @@ async fn main() {
}
}
}
EditEventMealsType::Edit(_meal) => todo!(),
EditEventMealsType::Edit(meal) => {
let meal_id = meal.meal_id;

// Check if Meal exists
if let Ok(meal) = food_base.get_event_meal(meal_id).await {
println!("Current State: \n");
if meal.event_id != event.event_id {
println!("The meal you are trying to edit does not belong to the event you ame editing. Maby check the given meal/event ID");
return;
}
}
}
},
EditEventType::Shopping(shopping_data) => match &shopping_data.edit_type {
EditEventShoppingType::Add(add_data) => match &add_data.edit_type {
EditEventShoppingAddType::Tour(tour_data) => {
let _ = food_base
.add_event_shopping_tour(
event_id.event_id,
event.event_id,
tour_data.store,
tour_data.date,
)
Expand All @@ -1297,7 +1306,7 @@ async fn main() {
EditEventShoppingAddType::SourceOverride(override_data) => {
let _ = food_base
.add_event_source_override(
event_id.event_id,
event.event_id,
override_data.source_id,
)
.await;
Expand All @@ -1314,7 +1323,7 @@ async fn main() {

let _ = food_base
.add_event_food_prep(
event_id.event_id,
event.event_id,
recipe.recipe_id.clone(),
prep_data.prep_date,
prep_data.use_start_date,
Expand Down Expand Up @@ -1381,7 +1390,7 @@ async fn main() {
EditEventShoppingEditType::SourceOverride(source_edit_data) => {
let _ = food_base
.update_event_ingredient_source_override(
event_id.event_id,
event.event_id,
source_edit_data.old_source_id,
source_edit_data.new_source_id,
)
Expand Down

0 comments on commit 2dabb57

Please sign in to comment.