diff --git a/src/main.rs b/src/main.rs index 6d835b4c..c27bfa89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -101,8 +101,6 @@ fn main() -> Result { info_file.final_message.unwrap_or_default(), )?; - let replacer = UrlReplacer::new(&args.base_url); - // Show the welcome message if the state file doesn't exist yet. if let Some(welcome_message) = info_file.welcome_message { match state_file_status { @@ -187,9 +185,14 @@ fn main() -> Result { if let Some(name) = name { app_state.set_current_exercise_by_name(&name)?; } - + let hint = app_state.current_exercise().hint; - println!("{}", replacer.replace(hint)); + if let Some(base_url) = args.base_url { + let replacer = UrlReplacer::new(base_url); + println!("{}", replacer.replace(hint)); + } else { + println!("{}", hint); + }; } // Handled in an earlier match. Some(Subcommands::Init | Subcommands::Dev(_)) => (), diff --git a/src/url_replacer.rs b/src/url_replacer.rs index 5b63e390..dac8852d 100644 --- a/src/url_replacer.rs +++ b/src/url_replacer.rs @@ -1,21 +1,17 @@ -pub struct UrlReplacer <'a> { - base_url: &'a Option +pub struct UrlReplacer { + base_url: String } const EN_BASE_URL: &str = "https://doc.rust-lang.org/book"; -impl <'a> UrlReplacer <'a> { - pub fn new(base_url: &'a Option) -> Self { +impl UrlReplacer { + pub fn new(base_url: String) -> Self { Self { base_url } } pub fn replace(&self, hint: &str) -> String { - if let Some(base_url) = self.base_url { - hint.replace(EN_BASE_URL, base_url) - } else { - hint.to_owned() - } + hint.replace(EN_BASE_URL, &self.base_url) } }