Skip to content
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

feat: hide stacktrace in case of failures #23

Merged
merged 3 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,80 @@ 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")
}

return when {
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)
}
}

Expand Down