New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Export Config with --generate-config
#54
Conversation
The review fixes and I'm gladly merging this PR. Thx! |
@@ -157,7 +157,7 @@ allprojects { | |||
} | |||
|
|||
detekt { | |||
config = "$project.projectDir/default-detekt-config.yml" | |||
config = "$project.projectDir/detekt-cli/src/main/resources/default-detekt-config.yml" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thats wrong. The config parameter should be used to locate your default-config from any path on your filesystem. If you have the default-config inside your resources (maven multi-module support), you should use the configResource
field eg. configResource = "default-detekt-config.yml"
which will be extracted from the resources
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just the local build.gradle
. From what I undernstand this is the local configuration of the gradle detekt plugin? Within this context, this path will always contain the configuration. Using configResource
does not work here, as the default-detekt-config.yml
only gets bundled into the detekt-cli
jar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, your right. I somehow thought this was the README and the users would get confused. :)
class ConfigExporter(val main: Main) { | ||
|
||
fun execute() { | ||
val defaultConfig = ClassLoader.getSystemClassLoader().getResourceAsStream("default-detekt-config.yml") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use javaClass.getResourceAsStream()
and explicitly throw an InvalidStateException if the inputstream is null
@@ -64,6 +68,9 @@ class Main { | |||
if (main.debug) { | |||
Debugger(main).execute() | |||
return | |||
} else if (main.generateConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's time to introduce an Executable
interface :) Something like:
val executable = when {
main.debug -> Debugger(main)
main.generateConfig -> ConfigExporter(main)
else -> Runner(main)
}
executable.execute()
Fixes #48.
--generate-config
is marked ashelp=True
to prevent the required option exception. But thejcommander.Parameter
class only cares for the existence of at least one of those and there is no further special treatment.