-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### What's done: - main runner It closes #1685
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
diktat-cli/src/main/kotlin/org/cqfn/diktat/DiktatMainRunner.kt
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,66 @@ | ||
package org.cqfn.diktat | ||
|
||
import org.cqfn.diktat.api.DiktatRuleSet | ||
import org.cqfn.diktat.api.DiktatRuleSetFactory | ||
import org.cqfn.diktat.ktlint.DiktatProcessorFactoryImpl | ||
import org.cqfn.diktat.ruleset.rules.DiktatRuleSetFactoryImpl | ||
import mu.KotlinLogging | ||
import org.apache.logging.log4j.LogManager | ||
import org.apache.logging.log4j.core.LoggerContext | ||
import org.slf4j.event.Level | ||
|
||
private val log = KotlinLogging.logger { } | ||
|
||
fun main() { | ||
// a temporary | ||
val logLevel = Level.ERROR | ||
// set log level | ||
LogManager.getContext(false) | ||
.let { it as LoggerContext } | ||
.also { ctx -> | ||
ctx.configuration.rootLogger.level = when (logLevel) { | ||
Level.ERROR -> org.apache.logging.log4j.Level.ERROR | ||
Level.WARN -> org.apache.logging.log4j.Level.WARN | ||
Level.INFO -> org.apache.logging.log4j.Level.INFO | ||
Level.DEBUG -> org.apache.logging.log4j.Level.DEBUG | ||
Level.TRACE -> org.apache.logging.log4j.Level.TRACE | ||
} | ||
} | ||
.updateLoggers() | ||
|
||
// default implementations | ||
val diktatRuleSetFactory = DiktatRuleSetFactoryImpl() | ||
val diktatProcessorFactory = DiktatProcessorFactoryImpl() | ||
|
||
// ruleSet | ||
val diktatRuleSet: DiktatRuleSet = diktatRuleSetFactory() | ||
val diktatProcessor: DiktatProcessor = diktatProcessorFactory(diktatRuleSet) | ||
|
||
val code = mutableListOf<String>() | ||
while (true) { | ||
val line = readln() | ||
if (line == "CHECK") { | ||
diktatProcessor.check( | ||
code = code.joinToString(), | ||
isScript = true | ||
) { error, _ -> | ||
println(error.toString()) | ||
} | ||
code.clear() | ||
} else if (line == "FIX") { | ||
val result = diktatProcessor.fix( | ||
code = code.joinToString(), | ||
isScript = true | ||
) { error, _ -> | ||
println(error.toString()) | ||
} | ||
code.clear() | ||
println("Formatted code:") | ||
println(result) | ||
} else if (line == "END") { | ||
break | ||
} else { | ||
code.add(line) | ||
} | ||
} | ||
} |