-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iss #24: use universal config in ambient7-analysis
- Loading branch information
Showing
10 changed files
with
239 additions
and
277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 0 additions & 37 deletions
37
ambient7-analysis/src/main/scala/ru/maizy/ambient7/analysis/AnalysisApp.scala
This file was deleted.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
ambient7-analysis/src/main/scala/ru/maizy/ambient7/analysis/AnalysisAppLauncher.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ru.maizy.ambient7.analysis | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2016-2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
|
||
import ru.maizy.ambient7.analysis.command.{ AggregateCo2Command, InitDbCommand } | ||
import ru.maizy.ambient7.core.config.ParsingError | ||
|
||
|
||
object AnalysisAppLauncher extends App { | ||
|
||
AnalysisConfigReader.readAppConfig(args) match { | ||
case Left(parsingError) => | ||
analysisLogger.error(ParsingError.formatErrorsForLog(parsingError)) | ||
Console.err.println(ParsingError.formatErrorsAndUsage(parsingError)) | ||
System.exit(2) | ||
|
||
case Right(opts) if opts.analysisSpecificOptions.isEmpty => | ||
Console.err.println("unknown command") | ||
System.exit(2) | ||
|
||
case Right(opts) => | ||
opts.analysisSpecificOptions.map(_.command).getOrElse("") match { | ||
case Some("init-db") => | ||
opts.mainDb match { | ||
case Some(dbOpts) => | ||
val res = InitDbCommand.run(dbOpts.url.getOrElse(""), dbOpts.user, dbOpts.password) | ||
System.exit(res.systemExitCode) | ||
case None => | ||
analysisLogger.error("db opts required") | ||
System.exit(2) | ||
} | ||
|
||
case Some("aggregate-co2") => | ||
val res = AggregateCo2Command.run(opts) | ||
System.exit(res.systemExitCode) | ||
|
||
case _ => | ||
Console.err.println("Unknown command") | ||
System.exit(2) | ||
} | ||
|
||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
ambient7-analysis/src/main/scala/ru/maizy/ambient7/analysis/AnalysisConfigReader.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package ru.maizy.ambient7.analysis | ||
|
||
import ru.maizy.ambient7.core.config.{ Ambient7Options, AnalysisSpecificOptions } | ||
import ru.maizy.ambient7.core.config.reader.{ DevicesConfigReader, InfluxDbConfigReader, MainDbConfigReader } | ||
import ru.maizy.ambient7.core.config.reader.UniversalConfigReader | ||
|
||
/** | ||
* Copyright (c) Nikita Kovaliov, maizy.ru, 2017 | ||
* See LICENSE.txt for details. | ||
*/ | ||
object AnalysisConfigReader | ||
extends UniversalConfigReader | ||
with DevicesConfigReader | ||
with InfluxDbConfigReader | ||
with MainDbConfigReader | ||
{ | ||
override def appName: String = "java -jar ambient7-analysis.jar" | ||
|
||
private def setCommand(opts: Ambient7Options, command: String): Ambient7Options = { | ||
val existingOpts = opts.analysisSpecificOptions.getOrElse(AnalysisSpecificOptions()) | ||
opts.copy(analysisSpecificOptions = Some(existingOpts.copy(command = Some(command)))) | ||
} | ||
|
||
override def fillReader(): Unit = { | ||
fillDevicesOptions() | ||
fillConfigOptions(requireConfig = true) | ||
fillInfluxDbOptions() | ||
fillDbOptions() | ||
|
||
cliParser.cmd("aggregate-co2") | ||
.action { (_, opts) => setCommand(opts, "aggregate-co2") } | ||
.text("\tcompute hourly co2 levels report") | ||
|
||
cliParser.cmd("init-db") | ||
.action { (_, opts) => setCommand(opts, "init-db") } | ||
.text("\tinitialize or upgrade db") | ||
|
||
() | ||
} | ||
|
||
fillReader() | ||
} |
133 changes: 0 additions & 133 deletions
133
ambient7-analysis/src/main/scala/ru/maizy/ambient7/analysis/AppOptions.scala
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.