From 8bd3cbfbba692d0bcc3e1cc247ff0ddbef1ac12b Mon Sep 17 00:00:00 2001 From: Adrian Borup Date: Tue, 26 Sep 2023 13:48:31 +0200 Subject: [PATCH] Ask which solution file to use when multiple are available --- Cargo.toml | 1 + src/solution.rs | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 61e0d14..62b7bfc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ serde = { version = "1", features = ["derive"] } scraper = "0.14" selectors = "0.22" self_update = "0.36" +dialoguer = "0.11" [dev-dependencies] dockertest = "0.3" diff --git a/src/solution.rs b/src/solution.rs index 5641402..01fe597 100644 --- a/src/solution.rs +++ b/src/solution.rs @@ -6,7 +6,7 @@ use std::{ }; use color_eyre::owo_colors::OwoColorize; -use eyre::Context; +use eyre::{Context, ContextCompat}; use crate::{ config::language::Language, @@ -107,7 +107,23 @@ fn resolve_solution_file_to_use( return Ok(file.clone()); } - eyre::bail!("Multiple solution files found. Specify which file to use with the --file option."); + let file_names = options + .iter() + .map(resolve_and_get_file_name) + .collect::>>() + .wrap_err("Failed to extract file names from solution folder")?; + + let selection = dialoguer::Select::with_theme(&dialoguer::theme::ColorfulTheme::default()) + .with_prompt("Multiple solution files found. Specify which file to use:") + .items(&file_names) + .default(0) + .interact() + .wrap_err("Failed to choose solution file")?; + + options + .get(selection) + .cloned() + .wrap_err("Selected option was invalid") } pub fn get_all_files_with_known_extension(