system file cealnsups rust4
authorBen Pfaff <blp@cs.stanford.edu>
Wed, 16 Jul 2025 14:54:21 +0000 (07:54 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Wed, 16 Jul 2025 14:54:21 +0000 (07:54 -0700)
rust/pspp/src/main.rs

index d82c5d4c2b11bd9403977c8d35af717fc6554771..f3f885d0855f1f99febe18aaa111c02e9658a1be 100644 (file)
@@ -67,6 +67,12 @@ struct Convert {
     #[arg(short = 'e', long, value_parser = parse_encoding)]
     encoding: Option<&'static Encoding>,
 
+    /// Password for decryption, with or without what SPSS calls "password encryption".
+    ///
+    /// Specify only for an encrypted system file.
+    #[clap(short, long)]
+    password: Option<String>,
+
     /// Maximum number of cases to print.
     #[arg(short = 'c', long = "cases")]
     max_cases: Option<u64>,
@@ -83,13 +89,15 @@ struct CsvOptions {
 }
 
 impl Convert {
-    fn warn(warning: anyhow::Error) {
-        eprintln!("warning: {warning}");
-    }
-
     fn run(self) -> Result<()> {
+        fn warn(warning: anyhow::Error) {
+            eprintln!("warning: {warning}");
+        }
+
         let (dictionary, _, cases) = ReaderOptions::new()
-            .open_file(&self.input, Self::warn)?
+            .with_encoding(self.encoding)
+            .with_password(self.password.clone())
+            .open_file(&self.input, warn)?
             .into_parts();
         let writer = match self.output {
             Some(path) => Box::new(File::create(path)?) as Box<dyn Write>,