Skip to content

Commit 94250d6

Browse files
author
Antonio Bennett
committed
Improve: Add note for existing flat files during Rust edit
- Detects old flat paths and suggests migration without auto-moving. - Helps users with pre-existing problems.
1 parent aa7401d commit 94250d6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cmds/edit.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ impl Command for EditCommand {
6262
/// `edit` handler
6363
async fn handler(m: &ArgMatches) -> Result<()> {
6464
use crate::{cache::models::Question, Cache};
65+
use crate::helper::suffix;
6566
use std::fs::{self, File};
6667
use std::io::Write;
6768
use std::path::Path;
@@ -108,6 +109,13 @@ use std::path::Path;
108109
let question: Question = qr?;
109110

110111
if *lang == "rust" {
112+
let flat_suffix = suffix(&lang).map_err(anyhow::Error::msg)?; // Since suffix returns Result<&str>
113+
let pick_replaced = conf.code.pick.replace("${fid}", &problem.fid.to_string()).replace("${slug}", &problem.slug.to_string());
114+
let flat_path_str = format!("{}/{}.{}", conf.storage.code()?, pick_replaced, flat_suffix);
115+
if Path::new(&flat_path_str).exists() {
116+
println!("Note: Existing flat file at {}. Consider migrating content to new subdir structure.", flat_path_str);
117+
}
118+
111119
let sanitized_slug = problem.slug.to_lowercase().replace(|c: char| !c.is_alphanumeric(), "_");
112120
let code_dir_str = format!("{}/{}-{}", conf.storage.code()?, problem.fid, sanitized_slug);
113121
let code_dir = Path::new(&code_dir_str);

0 commit comments

Comments
 (0)