You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@daffodil.apache.org by "stevedlawrence (via GitHub)" <gi...@apache.org> on 2023/02/03 18:19:00 UTC

[GitHub] [daffodil] stevedlawrence commented on a diff in pull request #948: Refactor how Main calls "generate c"

stevedlawrence commented on code in PR #948:
URL: https://github.com/apache/daffodil/pull/948#discussion_r1096111873


##########
daffodil-cli/src/main/scala/org/apache/daffodil/Main.scala:
##########
@@ -454,30 +454,37 @@ class CLIConf(arguments: Array[String]) extends scallop.ScallopConf(arguments) {
     footer("""|
               |Run 'daffodil generate <language> --help' for subcommand specific options""".stripMargin)
 
-    object c extends scallop.Subcommand("c") {
-      banner("""|Usage: daffodil generate c -s <schema> [-r <root>]
-                |                           [-c <file>] [-T<tunable>=<value>...]
-                |                           [outdir]
-                |
-                |Generate C code from a DFDL schema to parse or unparse data
-                |
-                |Generate Options:""".stripMargin)
-
-      descr("Generate C code from a DFDL schema")
+    // Takes language by name so we can pass it to scallop.Subcommand and interpolate it
+    // into strings without getting a puzzling java.lang.ClassCastException at runtime (class
+    // scala.collection.mutable.WrappedArray$ofRef cannot be cast to class java.lang.String)
+    class LanguageConf(languageArg: => String) extends scallop.Subcommand(languageArg) {
+      val language = languageArg
+
+      banner(s"""|Usage: daffodil generate $language -s <schema> [-r <root>]
+                 |                              [-c <file>] [-T<tunable>=<value>...]
+                 |                              [outdir]
+                 |
+                 |Generate ${language.toUpperCase} code from a DFDL schema to parse or unparse data

Review Comment:
   Thoughts on making `val language = languageArg.toUpperCase` and then just using `language` in the banner/options?
   
   That way if we ever support languages where the language name isn't as simple as the upper cased command then they can override it, e.g.:
   
   ```scala
   object rust extends LanguageConf("rust") {
     override val language = "Rust"
   }
   
   object rust extends LanguageConf("cpp") {
     override val language = "C++"
   } 
   
   object rust extends LanguageConf("csharp") {
     override val language = "C#"
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@daffodil.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org