LuciferYang commented on code in PR #46802:
URL: https://github.com/apache/spark/pull/46802#discussion_r1620243524


##########
core/src/main/scala/org/apache/spark/deploy/history/HistoryServerArguments.scala:
##########
@@ -44,47 +45,62 @@ private[history] class HistoryServerArguments(conf: 
SparkConf, args: Array[Strin
 
       case Nil =>
 
-      case _ =>
-        printUsageAndExit(1)
+      case other =>
+        val errorMsg = s"Unrecognized options: ${other.mkString(" ")}\n"
+        printUsageAndExit(1, errorMsg)
     }
   }
 
-   // This mutates the SparkConf, so all accesses to it must be made after 
this line
-   Utils.loadDefaultSparkProperties(conf, propertiesFile)
+  // This mutates the SparkConf, so all accesses to it must be made after this 
line
+  Utils.loadDefaultSparkProperties(conf, propertiesFile)
 
-  private def printUsageAndExit(exitCode: Int): Unit = {
-    // scalastyle:off println
-    System.err.println(
-      """
-      |Usage: HistoryServer [options]
-      |
-      |Options:
-      |  --properties-file FILE      Path to a custom Spark properties file.
-      |                              Default is conf/spark-defaults.conf.
-      |
-      |Configuration options can be set by setting the corresponding JVM 
system property.
-      |History Server options are always available; additional options depend 
on the provider.
-      |
-      |History Server options:
-      |
-      |  spark.history.ui.port              Port where server will listen for 
connections
-      |                                     (default 18080)
-      |  spark.history.acls.enable          Whether to enable view acls for 
all applications
-      |                                     (default false)
-      |  spark.history.provider             Name of history provider class 
(defaults to
-      |                                     file system-based provider)
-      |  spark.history.retainedApplications Max number of application UIs to 
keep loaded in memory
-      |                                     (default 50)
-      |FsHistoryProvider options:
-      |
-      |  spark.history.fs.logDirectory      Directory where app logs are stored
-      |                                     (default: file:/tmp/spark-events)
-      |  spark.history.fs.update.interval   How often to reload log data from 
storage
-      |                                     (in seconds, default: 10)
-      |""".stripMargin)
-    // scalastyle:on println
+  // scalastyle:off line.size.limit println
+  private def printUsageAndExit(exitCode: Int, error: String = ""): Unit = {
+    val configs = History.getClass.getDeclaredFields
+      .filter(f => classOf[ConfigEntry[_]].isAssignableFrom(f.getType))
+      .map { f =>
+        f.setAccessible(true)
+        f.get(History).asInstanceOf[ConfigEntry[_]]
+      }
+    val maxConfigLength = configs.map(_.key.length).max
+    val sb = new StringBuilder(
+      s"""
+         |${error}Usage: HistoryServer [options]

Review Comment:
   ```
   |$error
   |Usage: HistoryServer [options]
   ```
   
   Would it be possible to eliminate the '\n' in the definition of 'errorMsg' 
if it is changed in this way?
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to