Skip to content

Commit

Permalink
Merge pull request #80 from avborup/feature/select-solution-file
Browse files Browse the repository at this point in the history
Ask which solution file to use when multiple are available
  • Loading branch information
avborup committed Sep 26, 2023
2 parents cf5608f + 8bd3cbf commit 96e8945
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 18 additions & 2 deletions src/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
};

use color_eyre::owo_colors::OwoColorize;
use eyre::Context;
use eyre::{Context, ContextCompat};

use crate::{
config::language::Language,
Expand Down Expand Up @@ -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::<crate::Result<Vec<_>>>()
.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(
Expand Down

0 comments on commit 96e8945

Please sign in to comment.