This is an automated email from the ASF dual-hosted git repository.

slawrence pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/daffodil.git


The following commit(s) were added to refs/heads/main by this push:
     new 9b12912f5 Error if -T and -P options are used together in the CLI
9b12912f5 is described below

commit 9b12912f59140b1e934133e777a616b6f8fff702
Author: Steve Lawrence <[email protected]>
AuthorDate: Tue Mar 19 15:12:38 2024 -0400

    Error if -T and -P options are used together in the CLI
    
    When a parser is created with the CLI "save-parser" command, the values
    of the tunables are serialized along with the parser. When using the
    "parse", "unparse", or "performance" commands with the -P option to
    reload a saved parser, we use the serialized tunable values and ignore
    the -T option if provided. This can be confusing since there is no
    indication that the -T option is ignored.
    
    To avoid this, we now error if the -P and -T options are used together.
    Saved parsers must be rebuilt if you want to change tunable values.
    
    DAFFODIL-2880
---
 .../main/scala/org/apache/daffodil/cli/Main.scala  | 33 ++++++++++++++++------
 .../daffodil/cli/cliTest/TestCLITunables.scala     | 14 +++++++++
 2 files changed, 38 insertions(+), 9 deletions(-)

diff --git a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala 
b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
index 3e9477b3a..e18a14be3 100644
--- a/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
+++ b/daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
@@ -405,9 +405,14 @@ class CLIConf(arguments: Array[String], stdout: 
PrintStream, stderr: PrintStream
       descr = "Input file to parse. If not specified, or a value of -, reads 
from stdin.",
     )
 
-    requireOne(schema, parser) // must have one of --schema or --parser
-    conflicts(parser, List(rootNS)) // if --parser is provided, cannot also 
provide --root
-    validateFileIsFile(config) // --config must be a file that exists
+    // must have one of --schema or --parser
+    requireOne(schema, parser)
+
+    // if --parser is provided, cannot also provide --root or -T
+    conflicts(parser, List(rootNS, tunables))
+
+    // --config must be a file that exists
+    validateFileIsFile(config)
 
     validateOpt(debug, infile) {
       case (Some(_), Some("-")) | (Some(_), None) =>
@@ -510,9 +515,14 @@ class CLIConf(arguments: Array[String], stdout: 
PrintStream, stderr: PrintStream
       descr = "Input file to unparse. If not specified, or a value of -, reads 
from stdin.",
     )
 
-    requireOne(schema, parser) // must have one of --schema or --parser
-    conflicts(parser, List(rootNS)) // if --parser is provided, cannot also 
provide --root
-    validateFileIsFile(config) // --config must be a file that exists
+    // must have one of --schema or --parser
+    requireOne(schema, parser)
+
+    // if --parser is provided, cannot also provide --root or -T
+    conflicts(parser, List(rootNS, tunables))
+
+    // --config must be a file that exists
+    validateFileIsFile(config)
 
     validateOpt(debug, infile) {
       case (Some(_), Some("-")) | (Some(_), None) =>
@@ -706,9 +716,14 @@ class CLIConf(arguments: Array[String], stdout: 
PrintStream, stderr: PrintStream
       descr = "Input file or directory containing input files to parse or 
unparse",
     )
 
-    requireOne(schema, parser) // must have one of --schema or --parser
-    conflicts(parser, List(rootNS)) // if --parser is provided, cannot also 
provide --root
-    validateFileIsFile(config) // --config must be a file that exists
+    // must have one of --schema or --parser
+    requireOne(schema, parser)
+
+    // if --parser is provided, cannot also provide --root or -T
+    conflicts(parser, List(rootNS, tunables))
+
+    // --config must be a file that exists
+    validateFileIsFile(config)
 
     validateOpt(infosetType, schema) {
       case (Some(InfosetType.EXISA), None) =>
diff --git 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLITunables.scala
 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLITunables.scala
index b7fa8c745..659a2e1fd 100644
--- 
a/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLITunables.scala
+++ 
b/daffodil-cli/src/test/scala/org/apache/daffodil/cli/cliTest/TestCLITunables.scala
@@ -243,4 +243,18 @@ class TestCLITunables {
     }
   }
 
+  @Test def test_CLI_Parsing_ReloadingWithTunables(): Unit = {
+    val schema = path(
+      
"daffodil-test/src/test/resources/org/apache/daffodil/section06/entities/charClassEntities.dfdl.xsd",
+    )
+
+    withTempFile { parser =>
+      runCLI(args"save-parser -s $schema -r matrix $parser") { _ => 
}(ExitCode.Success)
+
+      runCLI(args"parse --parser $parser 
-TsuppressSchemaDefinitionWarnings=all") { cli =>
+        cli.expectErr("Option 'parser' conflicts with option 'T'")
+      }(ExitCode.Usage)
+    }
+  }
+
 }

Reply via email to