Skip to content

Commit

Permalink
fixup! Enable debug/trace for parse, unparse and test only
Browse files Browse the repository at this point in the history
- update usage string

DAFFODIL-1141
  • Loading branch information
olabusayoT committed Sep 25, 2024
1 parent a6276d1 commit 017b86d
Showing 1 changed file with 66 additions and 49 deletions.
115 changes: 66 additions & 49 deletions daffodil-cli/src/main/scala/org/apache/daffodil/cli/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,12 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream

// Parse Subcommand Options
object parse extends scallop.Subcommand("parse") {
banner("""|Usage: daffodil parse (-s <schema> [-r <root>] | -P <parser>)
| [-c <file>] [-D<variable>=<value>...] [-I <infoset_type>]
| [-o <output>] [--stream] [-T<tunable>=<value>...] [-V <mode>]
| [--trace | --debug <file>]
| [infile]
banner("""|Usage: daffodil parse (-s <schema> | -P <parser>) [PARSE_OPTS] [--] [infile]
|
|Parse a file, using either a DFDL schema or a saved parser
|
|-- can be used to separate command-line options from trailing arguments
|
|Parse Options:""".stripMargin)

descr("Parse data to a DFDL infoset")
Expand Down Expand Up @@ -375,8 +373,9 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
val rootNS = opt[RefQName](
"root",
argName = "node",
descr =
"Root element to use. Can be prefixed with {namespace}. Must be a top-level element. Defaults to first top-level element of DFDL schema."
descr = "Root element to use. Can be prefixed with {namespace}. " +
"Must be a top-level element. Defaults to first top-level element of DFDL schema. " +
"Only valid with the --schema option. Cannot be used with the --parser option."
)
val schema =
opt[URISchemaSource](
Expand All @@ -397,7 +396,8 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
name = 'T',
keyName = "tunable",
valueName = "value",
descr = "Tunable configuration options to change Daffodil's behavior"
descr = "Tunable configuration options to change Daffodil's behavior. " +
"Only valid with the --schema option. Cannot be used with the --parser option."
)
val validate: ScallopOption[ValidationMode.Type] = opt[ValidationMode.Type](
short = 'V',
Expand All @@ -408,9 +408,13 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
val debug = opt[Option[String]](
argName = "file",
descr =
"Enable the interactive debugger. Optionally, read initial debugger commands from [file] if provided."
"Enable the interactive debugger. Optionally, read initial debugger commands from [file] if provided. " +
"Cannot be used with --trace option. They are mutually exclusive options."
)(optionalValueConverter[String](a => a))
val trace = opt[Boolean](descr = "Run this program with verbose trace output")
val trace = opt[Boolean](
descr = "Run this program with verbose trace output. " +
"Cannot be used with the --debug option. They are mutually exclusive options."
)

val infile = trailArg[String](
required = false,
Expand Down Expand Up @@ -453,14 +457,12 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream

// Unparse Subcommand Options
object unparse extends scallop.Subcommand("unparse") {
banner("""|Usage: daffodil unparse (-s <schema> [-r <root>] | -P <parser>)
| [-c <file>] [-D<variable>=<value>...] [-I <infoset_type>]
| [-o <output>] [--stream] [-T<tunable>=<value>...] [-V <mode>]
| [--trace | --debug <file>]
| [infile]
banner("""|Usage: daffodil unparse (-s <schema> | -P <parser>) [--] [infile]
|
|Unparse an infoset file, using either a DFDL schema or a saved parser
|
|-- can be used to separate command-line options from trailing arguments
|
|Unparse Options:""".stripMargin)

descr("Unparse a DFDL infoset")
Expand Down Expand Up @@ -499,8 +501,9 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
val rootNS = opt[RefQName](
"root",
argName = "node",
descr =
"Root element to use. Can be prefixed with {namespace}. Must be a top-level element. Defaults to first top-level element of DFDL schema."
descr = "Root element to use. Can be prefixed with {namespace}. " +
"Must be a top-level element. Defaults to first top-level element of DFDL schema. " +
"Only valid with the --schema option. Cannot be used with the --parser option."
)
val schema =
opt[URISchemaSource](
Expand All @@ -520,7 +523,8 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
name = 'T',
keyName = "tunable",
valueName = "value",
descr = "Tunable configuration options to change Daffodil's behavior"
descr = "Tunable configuration options to change Daffodil's behavior. " +
"Only valid with the --schema option. Cannot be used with the --parser option."
)
val validate: ScallopOption[ValidationMode.Type] = opt[ValidationMode.Type](
short = 'V',
Expand All @@ -531,10 +535,13 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
val debug = opt[Option[String]](
argName = "file",
descr =
"Enable the interactive debugger. Optionally, read initial debugger commands from [file] if provided."
"Enable the interactive debugger. Optionally, read initial debugger commands from [file] if provided. " +
"Cannot be used with --trace option. They are mutually exclusive options."
)(optionalValueConverter[String](a => a))
val trace = opt[Boolean](descr = "Run this program with verbose trace output")

val trace = opt[Boolean](
descr = "Run this program with verbose trace output. " +
"Cannot be used with the --debug option. They are mutually exclusive options."
)
val infile = trailArg[String](
required = false,
descr = "Input file to unparse. If not specified, or a value of -, reads from stdin."
Expand Down Expand Up @@ -570,12 +577,12 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream

// Save Parser Subcommand Options
object save extends scallop.Subcommand("save-parser") {
banner("""|Usage: daffodil save-parser -s <schema> [-r <root>]
| [-c <file>] [-D<variable>=<value>...] [-T<tunable>=<value>...]
| [outfile]
banner("""|Usage: daffodil save-parser -s <schema> [SAVE_PARSER_OPTIONS] [--] [outfile]
|
|Create and save a parser using a DFDL schema
|
|-- can be used to separate command-line options from trailing arguments
|
|Save Parser Options:""".stripMargin)

descr("Save a Daffodil parser for reuse")
Expand Down Expand Up @@ -629,11 +636,13 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
// Test Subcommand Options
object test extends scallop.Subcommand("test") {
banner(
"""|Usage: daffodil test [-I <implementation>] [-l] [-r] [-i] [-d <file> | -d -- | -t] <tdmlfile> [testnames...]
|
|List or execute tests in a TDML file
|
|Test Options:""".stripMargin
"""|Usage: daffodil test [TEST_OPTIONS] [--] <tdmlfile> [testnames...]
|
|List or execute tests in a TDML file
|
|-- can be used to separate command-line options from trailing arguments
|
|Test Options:""".stripMargin
)

descr("List or execute TDML tests")
Expand All @@ -654,10 +663,12 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
argName = "file",
descr =
"Enable the interactive debugger. Optionally, read initial debugger commands from [file] if provided. " +
"To use debug without a file, one must supply '--' inplace of file " +
"i.e 'daffodil test -d -- path/to/tests.tdml'"
"Cannot be used with --trace option. They are mutually exclusive options."
)(optionalValueConverter[String](a => a))
val trace = opt[Boolean](descr = "Run this program with verbose trace output")
val trace = opt[Boolean](
descr = "Run this program with verbose trace output. " +
"Cannot be used with the --debug option. They are mutually exclusive options."
)
val tdmlfile =
trailArg[String](required = true, descr = "Test Data Markup Language (TDML) file")
val testnames = trailArg[List[String]](
Expand All @@ -670,15 +681,15 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream

// Performance Subcommand Options
object performance extends scallop.Subcommand("performance") {
banner("""|Usage: daffodil performance (-s <schema> [-r <root>] | -P <parser>)
| [-c <file>] [-D<variable>=<value>...] [-I <infoset_type>]
| [-N <number>] [-t <threads>] [-T<tunable>=<value>...]
| [-u] [-V <mode>]
| <infile>
banner(
"""|Usage: daffodil performance (-s <schema> | -P <parser>) [PERFORMANCE_OPTIONS] [--] <infile>
|
|Run a performance test, using either a DFDL schema or a saved parser
|
|Performance Options:""".stripMargin)
|-- can be used to separate command-line options from trailing arguments
|
|Performance Options:""".stripMargin
)

descr("Run performance test")
helpWidth(width)
Expand Down Expand Up @@ -718,8 +729,9 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
val rootNS = opt[RefQName](
"root",
argName = "node",
descr =
"Root element to use. Can be prefixed with {namespace}. Must be a top-level element. Defaults to first top-level element of DFDL schema."
descr = "Root element to use. Can be prefixed with {namespace}. " +
"Must be a top-level element. Defaults to first top-level element of DFDL schema. " +
"Only valid with the --schema option. Cannot be used with the --parser option."
)
val schema =
opt[URISchemaSource](
Expand All @@ -739,7 +751,8 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
name = 'T',
keyName = "tunable",
valueName = "value",
descr = "Tunable configuration options to change Daffodil's behavior"
descr = "Tunable configuration options to change Daffodil's behavior. " +
"Only valid with the --schema option. Cannot be used with the --parser option."
)
val unparse = opt[Boolean](
default = Some(false),
Expand Down Expand Up @@ -794,13 +807,15 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream
extends scallop.Subcommand(languageArg) {

val language = languageArg
banner(s"""|Usage: daffodil generate $language -s <schema> [-r <root>]
| [-c <file>] [-T<tunable>=<value>...]
| [outdir]
banner(
s"""|Usage: daffodil generate $language -s <schema> [GENERATE_OPTIONS] [--] [outdir]
|
|Generate $languageName code from a DFDL schema to parse or unparse data
|
|Generate Options:""".stripMargin)
|-- can be used to separate command-line options from trailing arguments
|
|Generate Options:""".stripMargin
)
descr(s"Generate $languageName code from a DFDL schema")
helpWidth(width)

Expand Down Expand Up @@ -847,10 +862,12 @@ class CLIConf(arguments: Array[String], stdout: PrintStream, stderr: PrintStream

// Encode or decode EXI Subcommand Options
object exi extends scallop.Subcommand("exi") {
banner("""|Usage: daffodil exi [-d] [-s <schema>] [-o <output>] [infile]
banner("""|Usage: daffodil exi [EXI_OPTIONS] [--] [infile]
|
|Encode/decode an XML file with EXI. If a schema is specified, it will use schema aware encoding/decoding.
|
|-- can be used to separate command-line options from trailing arguments
|
|EncodeEXI Options:""".stripMargin)

descr("Encode an XML file with EXI")
Expand Down Expand Up @@ -1034,9 +1051,9 @@ class Main(
}

def withDebugOrTrace(
proc: DFDL.DataProcessor,
traceArg: ScallopOption[Boolean],
debugArg: ScallopOption[Option[String]]
proc: DFDL.DataProcessor,
traceArg: ScallopOption[Boolean],
debugArg: ScallopOption[Option[String]]
): DFDL.DataProcessor = {
(traceArg() || debugArg.isDefined) match {
case true => {
Expand Down

0 comments on commit 017b86d

Please sign in to comment.