Skip to content

Commit

Permalink
Format according to ktlint+detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvisser committed Sep 11, 2023
1 parent bf99684 commit 1af94f2
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ class ZshAutocompletionGenerator(private val template: ZshAutocompletionTemplate

return buildString {
appendLine(SHEBANG)
functions.forEach { appendLine(it) }
loadLinesForResource("footer.sh").forEach { appendLine(it) }
functions.forEach(::appendLine)
loadLinesForResource().forEach(::appendLine)
}
}

private fun loadLinesForResource(resourceFile: String) =
ZshAutocompletionGenerator::class.java.getResourceAsStream("/autocompletion/zsh/$resourceFile")
private fun loadLinesForResource() =
ZshAutocompletionGenerator::class.java.getResourceAsStream("/autocompletion/zsh/footer.sh")
?.bufferedReader()?.lines()
?: throw IllegalStateException("Cannot find $resourceFile for the autocompletion script")
?: error("Cannot find footer.sh for the autocompletion script")

/**
* This function generates a ZSH function for a command and calls this function recursively for all of its subcommands.
* This function generates a ZSH function for a command,
* and calls this function recursively for all of its subcommands.
* @return A list containing all generated functions, ordered by hierarchy top-down.
*/
private fun generateFunctionForCommandsRecursively(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ private const val AUTOCOMPLETION_FUNCTION_PREFIX = "function:"
class ZshAutocompletionTemplate {

/**
* Generates a ZSH function for a command containing either subcommands or positional parameters and possibly options(/flags).
* Generates a ZSH function for a command containing either subcommands
* or positional parameters and possibly options(/flags).
*/
fun applyForCommand(
functionName: String,
Expand Down Expand Up @@ -145,12 +146,13 @@ function $functionName() {
}

/**
* This data class holds the spec which will be added to ZSH's _arguments method, and the action describes what's done when a certain argument spec is matched.
* This data class holds the spec which will be added to ZSH's _arguments method,
* and the action describes what's done when a certain argument spec is matched.
*/
data class ArgumentSpecActionPair(val spec: String, val action: String? = null)

sealed interface AutoCompleteAction
object NoAction : AutoCompleteAction
data object NoAction : AutoCompleteAction
data class FunctionCallAction(val functionName: String) : AutoCompleteAction
data class StaticValuesAction(val staticValues: String) : AutoCompleteAction
}
3 changes: 2 additions & 1 deletion ret-core/src/main/kotlin/io/rabobank/ret/IntelliSearch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ data class FilterRound(val filter: String, val startIndex: Int, val endIndex: In
/**
* Match results like IntelliJ
*
* This class is used to match a string of characters to a possible candidate, based on partial string matching. The matching copies the behaviour of e.g. searching for classes in IntelliJ.
* This class is used to match a string of characters to a possible candidate, based on partial string matching.
* The matching copies the behaviour of e.g. searching for classes in IntelliJ.
*
* Example: "as" will positively match with "Admin Service" or "admin-service", and so will "adser".
*/
Expand Down
6 changes: 4 additions & 2 deletions ret-core/src/main/kotlin/io/rabobank/ret/RetContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import io.quarkus.runtime.annotations.RegisterForReflection
* Context of the current RET execution
*
* This class is used to pass information about the context to plugins. Those in turn can use it to base logic upon.
* Note that this class needs to be registered for reflection in your plugin. To do that: add the annotation `@RegisterForReflection(targets = [RetContext::class])` to your entry command.
* Note that this class needs to be registered for reflection in your plugin.
* To do that: add the annotation `@RegisterForReflection(targets = [RetContext::class])` to your entry command.
* @property command the full command, as ran in the terminal. This is used to determine which plugin should be loaded.
* @property environment the environment from which the RET command is ran. This is a custom environment variable, set by the caller. By default, it is "CLI".
* @property environment the environment from which the RET command is ran.
* This is a custom environment variable, set by the caller. By default, it is "CLI".
* @property gitRepository the Git repository, if RET was called from a Git directory.
* @property gitBranch the current Git branch, if RET was called from a Git repository.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package io.rabobank.ret.configuration
/**
* Configuration Property for user configs
*
* Used for user configurations that can be used by RET plugins. For example: user specific parts in a URL, or personal access tokens.
* Used for user configurations that can be used by RET plugins.
* For example: user specific parts in a URL, or personal access tokens.
* @property key the name of the config property.
* @property prompt the message to the user, specifying what should be provided for this config property.
* @property required tells the user this is a mandatory field which cannot be skipped.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class RetConfig(
fun remove(key: String) = properties.remove(key)

/**
* Configure all defined configuration properties, based on the provided function and saves to the configuration file.
* Configure all defined configuration properties, based on the provided function,
* and saves to the configuration file.
* This is automatically called when initializing a plugin, so you normally do not call this yourself.
*/
override fun configure(function: (ConfigurationProperty) -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import picocli.CommandLine
* Version Provider for PicoCLI
*
* This class provides the version info for the entry command. This will be displayed when executing `ret -v`.
* This version flag is only available at the root command `ret` by default, but you could do something similar for your plugin.
* This version flag is only available at the root command `ret` by default,
* but you could do something similar for your plugin.
*/
@Unremovable
@ApplicationScoped
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import picocli.CommandLine.Command
import picocli.CommandLine.Option

/**
* Command to be mixed in (@Mixin) with other commands that use some type of contaext awareness for autocompletion (e.g. via [io.rabobank.ret.RetContext]).
* Mixing in this command will automatically add a flag for ignoring the context, which can be read out and used when performing custom autocompletion logic.
* Command to be mixed in (@Mixin) with other commands that use some type of contaext awareness for autocompletion
* (e.g. via [io.rabobank.ret.RetContext]).
* Mixing in this command will automatically add a flag for ignoring the context,
* which can be read out and used when performing custom autocompletion logic.
*/
@Command
class ContextAwareness {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class ConfigureProjectCommand(
if (retConfig["projects"] == null) {
retConfig["projects"] = listOf(Project(workingDir.name, workingDir.absolutePath))
} else {
@Suppress("UNCHECKED_CAST") val projectsMap = retConfig["projects"] as MutableList<Project>
@Suppress("UNCHECKED_CAST")
val projectsMap = retConfig["projects"] as MutableList<Project>
projectsMap += Project(workingDir.name, workingDir.absolutePath)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import picocli.CommandLine.Spec
/**
* Plugin Configure Command
*
* This is a mandatory sub command for any RET plugin that you create. RET will use it when executing `ret plugin configure your-plugin`.
* With this, RET will be able to run the plugin commands, automatically add autocompletion for the plugin, and prompt the user for any property that needs to be configured.
* This is a sub command for any RET plugin that you create.
* RET will use it when executing `ret yourPlugin configure`.
*
* With this, RET will prompt the user for any property that needs to be configured.
*/
@Command(
name = "configure",
Expand Down Expand Up @@ -50,7 +52,8 @@ class PluginConfigureCommand(
private fun storePluginConfiguration(pluginName: String) {
var hasPluginSpecificConfig = false
val pluginConfigFile = config.pluginConfigDirectory().resolve("$pluginName.json").toFile()
val pluginConfig = if (pluginConfigFile.exists()) objectMapper.readValue<Map<String, Any?>>(pluginConfigFile) else emptyMap()
val pluginConfig =
if (pluginConfigFile.exists()) objectMapper.readValue<Map<String, Any?>>(pluginConfigFile) else emptyMap()
val answers = pluginConfig.toMutableMap()

config.configure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import kotlin.io.path.createDirectories
/**
* Plugin Initialize Command
*
* This is a mandatory sub command for any RET plugin that you create. RET will use it when executing `ret plugin initialize your-plugin`.
* With this, RET will be able to run the plugin commands, automatically add autocompletion for the plugin, and prompt the user for any property that needs to be configured.
* This is a mandatory sub command for any RET plugin that you create.
* RET will use it when executing `ret plugin initialize your-plugin`.
*
* With this, RET will be able to run the plugin commands and automatically add autocompletion for the plugin.
*/
@Command(
name = "initialize",
Expand Down

0 comments on commit 1af94f2

Please sign in to comment.