diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 7631b2c..60dff89 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -50,9 +50,10 @@ This is a modular single-binary Rust utility that fetches Antares B2B product da **Artifacts:** - `temp/antares.json` - saved in `temp/` after each successful API fetch; directory created auto if missing +- **Cleanup**: `temp/` directory is automatically deleted after Excel export (unless `--debug` flag is set) - Excel export path is configured via the `OUT` env var; parent directory created auto if missing - `log/{YYYY-MM-DD}.log` - daily logs; `log/` directory created auto if missing -- `.gitignore` excludes: `*.json`, `*.xlsx`, `.env`, `/out`, `/log` +- `.gitignore` excludes: `*.json`, `*.xlsx`, `.env`, `/out`, `/log`, `/temp` **Excel export (`src/tools/excel.rs`):** - Not a generic dump; maps selected Antares fields to fixed column layout per business rules @@ -75,3 +76,7 @@ This is a modular single-binary Rust utility that fetches Antares B2B product da - Uses `reqwest::blocking::Client` with 600-second timeout (in `src/tools/request.rs`) - No async runtime; synchronous flow is intentional - Only change to async if architecture overhaul is deliberate + +**CLI Arguments:** +- `--config /path/to/.env` - Load config from custom location (defaults to `.env` in current directory) +- `--debug` - Enable debug mode: preserves `temp/` directory for inspection, no cleanup after export diff --git a/src/main.rs b/src/main.rs index 3590706..1df66bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,9 +24,14 @@ fn main() -> Result<(), Box> { let logger = Logger::init()?; logger.info("Starting Antares data export"); - // Parse CLI arguments for --config flag + // Parse CLI arguments for --config and --debug flags let args: Vec = std::env::args().collect(); let config_path = parse_config_arg(&args); + let debug_mode = args.contains(&"--debug".to_string()); + + if debug_mode { + logger.debug("Debug mode enabled - temp files will be preserved"); + } let env_config = load_env_config(config_path) .map_err(|e| { @@ -116,6 +121,18 @@ fn main() -> Result<(), Box> { } } + // Clean up temp directory unless in debug mode + if !debug_mode { + match fs::remove_dir_all(&temp_dir) { + Ok(_) => { + logger.debug(&format!("Cleaned up temp directory: {:?}", temp_dir)); + } + Err(e) => { + logger.warn(&format!("Failed to remove temp directory '{:?}': {}", temp_dir, e)); + } + } + } + logger.info("Export process completed successfully"); Ok(()) }