Skip to content

Commit

Permalink
make service optional in link
Browse files Browse the repository at this point in the history
  • Loading branch information
Milo123459 committed Nov 15, 2024
1 parent f03ddd7 commit f62a64c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/commands/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt::Display;

use crate::{
errors::RailwayError,
util::prompt::{fake_select, prompt_options},
util::prompt::{fake_select, prompt_options, prompt_options_skippable},
};

use super::{
Expand Down Expand Up @@ -91,21 +91,22 @@ fn select_service(
})
.cloned()
.collect::<Vec<NormalisedService>>();

let service = if !useful_services.is_empty() {
Some(if let Some(service) = service {
if let Some(service) = service {
let service_norm = useful_services.iter().find(|s| {
(s.name.to_lowercase() == service.to_lowercase())
|| (s.id.to_lowercase() == service.to_lowercase())
});
if let Some(service) = service_norm {
fake_select("Select a service", &service.name);
service.clone()
Some(service.clone())
} else {
return Err(RailwayError::ServiceNotFound(service).into());
}
} else {
prompt_options("Select a service", useful_services)?
})
prompt_options_skippable("Select a service <esc to skip>", useful_services)?
}
} else {
None
};
Expand Down
8 changes: 8 additions & 0 deletions src/util/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ pub fn prompt_options<T: Display>(message: &str, options: Vec<T>) -> Result<T> {
.context("Failed to prompt for options")
}

pub fn prompt_options_skippable<T: Display>(message: &str, options: Vec<T>) -> Result<Option<T>> {
let select = inquire::Select::new(message, options);
select
.with_render_config(Configs::get_render_config())
.prompt_skippable()
.context("Failed to prompt for options")
}

pub fn prompt_text(message: &str) -> Result<String> {
let select = inquire::Text::new(message);
select
Expand Down

0 comments on commit f62a64c

Please sign in to comment.