Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3785475
D2753.id6990.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
D2753.id6990.diff
View Options
diff --git a/fantoir-datasource/src/commands/fetch/mod.rs b/fantoir-datasource/src/commands/fetch/mod.rs
--- a/fantoir-datasource/src/commands/fetch/mod.rs
+++ b/fantoir-datasource/src/commands/fetch/mod.rs
@@ -44,6 +44,7 @@
let exit_code = match unzip(&target_path, overwrite).await {
Ok(path) => {
println!("FANTOIR_FILE={}", &path);
+ println!("FANTOIR_TABLE={}", suggest_fantoir_table(&path));
0
}
@@ -58,6 +59,16 @@
exit(exit_code);
}
+/// Suggests a FANTOIR table name based on the file version
+fn suggest_fantoir_table(filename: &str) -> String {
+ assert_eq!(11, filename.len(), "Fantoir filename is expected to have 11 characters.");
+
+ let month: i8 = filename[7..=8].parse().unwrap();
+ let year = 2000 + filename[9..=10].parse::<i32>().unwrap();
+
+ format!("fantoir_{}{}", year, month)
+}
+
/// Determines a temporary location where to save the FANTOIR file ZIP archive
fn get_fantoir_zip_path() -> PathBuf {
let filename = format!("fantoir-download-{}.zip", Utc::now().timestamp());
@@ -122,3 +133,19 @@
.max() // The most recent
.unwrap()
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn test_suggest_fantoir_table () {
+ assert_eq!("fantoir_202210", &suggest_fantoir_table("FANTOIR1022"))
+ }
+
+ #[test]
+ #[should_panic]
+ fn test_suggest_fantoir_table_with_bogus_filename () {
+ suggest_fantoir_table("FOO");
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Nov 27, 08:52 (20 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2266598
Default Alt Text
D2753.id6990.diff (1 KB)
Attached To
Mode
D2753: Suggest FANTOIR_TABLE value in fetch command
Attached
Detach File
Event Timeline
Log In to Comment