diff --git a/Dockerfile b/Dockerfile index e1fe9f4..3b07814 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,6 @@ FROM adoptopenjdk/openjdk11:jdk-11.0.11_9-alpine-slim RUN apk update && \ - apk add --no-cache jq -COPY /build/distributions/google-play-cli /usr/local/ \ No newline at end of file + apk add --no-cache jq \ + apk add --no-cache unzip +COPY /build/distributions/google-play-cli /usr/local/ +RUN chmod +x /usr/local/google-play-cli \ No newline at end of file diff --git a/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt b/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt index dac1c94..4d63dd0 100644 --- a/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt +++ b/src/main/kotlin/com/github/vacxe/googleplaycli/core/BaseCommand.kt @@ -5,33 +5,51 @@ import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.validate import com.github.vacxe.googleplaycli.PlayStoreApi +import com.google.api.client.googleapis.json.GoogleJsonResponseException import java.io.ByteArrayInputStream import java.io.File import java.io.FileInputStream import java.io.InputStream import java.security.InvalidParameterException +import kotlin.system.exitProcess -abstract class BaseCommand(name: String, actionDescription: String = "") : CliktCommand(name = name, help = actionDescription) { +abstract class BaseCommand(name: String, actionDescription: String = "") : + CliktCommand(name = name, help = actionDescription) { - private val serviceAccountJsonFile: String by option("--config-file", "-cf", help = "service account json file path") - .default(System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE") - ?: "") + private val serviceAccountJsonFile: String by option( + "--config-file", + "-cf", + help = "service account json file path" + ) + .default( + System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_FILE") + ?: "" + ) - private val serviceAccountJsonContent: String by option("--config-content", "-cc", help = "service account json content") - .default(System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT") - ?: "") + private val serviceAccountJsonContent: String by option( + "--config-content", + "-cc", + help = "service account json content" + ) + .default( + System.getenv("PLAYSTORE_SERVICE_ACCOUNT_JSON_CONTENT") + ?: "" + ) val packageName: String by option("--package-name", "-p", help = "package name (example: com.my.app)") - .default(System.getenv("APP_PACKAGE_NAME") ?: "") - .validate { require(it.isNotEmpty()) { "Please provide a valid $help" } } + .default(System.getenv("APP_PACKAGE_NAME") ?: "") + .validate { require(it.isNotEmpty()) { "Please provide a valid $help" } } + + private val debug: String by option("--debug", help = "enable debug logs") + .default("false") private val serviceAccountInputStream: InputStream get() { - if(serviceAccountJsonFile.isNotEmpty() && serviceAccountJsonContent.isNotEmpty()) { + if (serviceAccountJsonFile.isNotEmpty() && serviceAccountJsonContent.isNotEmpty()) { throw InvalidParameterException("Service account file or content can't be specified together") } - if(serviceAccountJsonFile.isEmpty() && serviceAccountJsonContent.isEmpty()) { + if (serviceAccountJsonFile.isEmpty() && serviceAccountJsonContent.isEmpty()) { throw InvalidParameterException("Service account File or Content need to be specified") } @@ -39,18 +57,28 @@ abstract class BaseCommand(name: String, actionDescription: String = "") : Clikt serviceAccountJsonContent.isNotEmpty() -> ByteArrayInputStream(serviceAccountJsonContent.toByteArray()) serviceAccountJsonFile.isNotEmpty() -> { val serviceAccountFile = File(serviceAccountJsonFile) - if(!serviceAccountFile.exists()) + if (!serviceAccountFile.exists()) throw InvalidParameterException("Service account file $serviceAccountJsonFile not exist") FileInputStream(serviceAccountFile) } + else -> throw InvalidParameterException("Service account input stream can't be defined") } } final override fun run() { val manager = PlayStoreApi(serviceAccountInputStream, packageName) - run(manager)?.let { - println(it) + try { + run(manager)?.let { + println(it) + } + } catch (e: GoogleJsonResponseException) { + if (debug.toBoolean()) { + e.printStackTrace() + } else { + println(e.content) + } + exitProcess(1) } }