Skip to content

Commit d38fb0a

Browse files
[x2cpg] Show usage on error for command line arguments (#5620)
1 parent 0f8214e commit d38fb0a

File tree

1 file changed

+6
-3
lines changed
  • joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg

1 file changed

+6
-3
lines changed

joern-cli/frontends/x2cpg/src/main/scala/io/joern/x2cpg/X2Cpg.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package io.joern.x2cpg
22

33
import io.joern.x2cpg.X2Cpg.{applyDefaultOverlays, withErrorsToConsole}
4-
import io.joern.x2cpg.frontendspecific.FrontendArgsDelimitor
54
import io.joern.x2cpg.layers.{Base, CallGraph, ControlFlow, TypeRelations}
65
import io.shiftleft.codepropertygraph.generated.Cpg
76
import io.shiftleft.semanticcpg.layers.{LayerCreator, LayerCreatorContext}
87
import io.shiftleft.semanticcpg.utils.FileUtil
98
import org.slf4j.LoggerFactory
10-
import scopt.OParser
9+
import scopt.{DefaultOParserSetup, OParser, OParserSetup}
1110

1211
import java.io.PrintWriter
1312
import java.nio.file.{Files, Paths}
@@ -262,6 +261,10 @@ object X2Cpg {
262261

263262
private val logger = LoggerFactory.getLogger(X2Cpg.getClass)
264263

264+
private val oParserSetup: OParserSetup = new DefaultOParserSetup {
265+
override def showUsageOnError: Option[Boolean] = Some(true)
266+
}
267+
265268
/** Parse commands line arguments in `args` using an X2Cpg command line parser, extended with the frontend specific
266269
* options in `frontendSpecific` with the initial configuration set to `initialConf`. On success, the configuration
267270
* is returned wrapped into an Option. On failure, error messages are printed and, `None` is returned.
@@ -272,7 +275,7 @@ object X2Cpg {
272275
initialConf: R
273276
): Option[R] = {
274277
val parser = commandLineParser(frontendSpecific)
275-
OParser.parse(parser, args, initialConf)
278+
OParser.parse(parser, args, initialConf, oParserSetup)
276279
}
277280

278281
/** Create a command line parser that can be extended to add options specific for the frontend.

0 commit comments

Comments
 (0)