Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit e1419a6

Browse files
committed
Added CLI arguments for password (not recommended) and startup plugin runs. Fixed a bug in the plugin framework crashing.
1 parent a576112 commit e1419a6

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

src/main/scala/org/codeoverflow/chatoverflow/Launcher.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,36 @@ object Launcher extends WithLogger {
1919
def main(args: Array[String]): Unit = {
2020
parse(args) { config =>
2121

22+
// Set globally available plugin data path
2223
this.pluginDataPath = config.pluginDataPath
2324

2425
// The complete project visible trough one single instance
2526
val chatOverflow = new ChatOverflow(config.pluginFolderPath,
2627
config.configFolderPath, config.requirementPackage, config.requirePasswordOnStartup, config.pluginLogOutputOnConsole)
2728

29+
// Initialize chat overflow
2830
chatOverflow.init()
2931

32+
// Login if a password is specified
33+
if (config.loginPassword.nonEmpty && !chatOverflow.isLoaded) {
34+
chatOverflow.credentialsService.setPassword(config.loginPassword)
35+
chatOverflow.load()
36+
}
37+
38+
// Start plugins if specified
39+
// TODO: Move this down after server start when the REPL is history
40+
if (chatOverflow.isLoaded && config.startupPlugins.nonEmpty) {
41+
for (instanceName <- config.startupPlugins) {
42+
val instance = chatOverflow.pluginInstanceRegistry.getPluginInstance(instanceName)
43+
44+
if (instance.isEmpty) {
45+
println(s"No plugin instance named '$instanceName' was registered.")
46+
} else {
47+
instance.get.start()
48+
}
49+
}
50+
}
51+
3052
// Launch UI
3153
config.ui match {
3254
case UI.GUI =>

src/main/scala/org/codeoverflow/chatoverflow/framework/PluginFramework.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class PluginFramework(pluginDirectoryPath: String) extends WithLogger {
9191
logger info s"Successfully tested instantiation of plugin '${plugin.getName}'"
9292
pluginTypes += plugin
9393
} catch {
94-
case _: Exception => logger warn s"Error while test init of plugin '${plugin.getName}'."
94+
// Note that we catch not only exceptions, but also errors like NoSuchMethodError. Deep stuff
95+
case _: Error => logger warn s"Error while test init of plugin '${plugin.getName}'."
96+
case _: Exception => logger warn s"Exception while test init of plugin '${plugin.getName}'."
9597
}
9698
}
9799
}

src/main/scala/org/codeoverflow/chatoverflow/ui/CLI.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,16 @@ object CLI {
3030
opt[String]('r', "requirementPackage").action((x, c) =>
3131
c.copy(requirementPackage = x)).text("path to the package where all requirements are defined")
3232

33-
// Subject of change. After GUI will be -l (for requireLogin)
33+
// Subject of change. After GUI will be -l (for login)
3434
opt[Unit]('n', "noPassword").action((_, c) =>
3535
c.copy(requirePasswordOnStartup = false)).text("set this flag to disable password checking on framework startup")
3636

37+
opt[String]('l', "login").action((x, c) =>
38+
c.copy(loginPassword = x.toCharArray)).text("the password to login to chat overflow (not recommended, has to be combined with -n)")
39+
40+
opt[Seq[String]]('s', "start").action((x, c) =>
41+
c.copy(startupPlugins = x)).text("a comma-separated list of plugin instances to start after login (has to be combined with -n and -l)")
42+
3743
opt[String]('d', "pluginDataFolder").action((x, c) =>
3844
c.copy(pluginDataPath = x)).text("path to the data folder, accessible from within plugins")
3945

@@ -73,7 +79,9 @@ object CLI {
7379
requirePasswordOnStartup: Boolean = true,
7480
pluginDataPath: String = "data",
7581
webServerPort: Int = 2400,
76-
pluginLogOutputOnConsole: Boolean = true)
82+
pluginLogOutputOnConsole: Boolean = true,
83+
loginPassword: Array[Char] = Array[Char](),
84+
startupPlugins: Seq[String] = Seq[String]())
7785

7886
object UI extends Enumeration {
7987
type UI = Value

0 commit comments

Comments
 (0)