Skip to content

Instantly share code, notes, and snippets.

@mkj-gram
Last active July 9, 2020 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mkj-gram/a5e19b3389563183ad0516438be16df9 to your computer and use it in GitHub Desktop.
Save mkj-gram/a5e19b3389563183ad0516438be16df9 to your computer and use it in GitHub Desktop.
Command Builder
package com.example.mylibrary
/** CommandBuilderBase contains options common for D8 and R8. */
abstract class CommandBuilderBase {
internal var minApi: Int = 0
internal var inputs: MutableList<String> = mutableListOf()
abstract fun getCommandName(): String
abstract fun getExtraArgs(): String
fun build(): String {
val inputArgs = inputs.joinToString(separator = " ")
return "${getCommandName()} --min-api=$minApi $inputArgs ${getExtraArgs()}"
}
}
fun <T : CommandBuilderBase> T.setMinApi(api: Int): T {
minApi = api
return this
}
fun <T : CommandBuilderBase> T.addInput(input: String): T {
inputs.add(input)
return this
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment