Skip to content

Commit

Permalink
[NAVAND-3174] Upgrade services-cli (#1593)
Browse files Browse the repository at this point in the history
* handle input from Stdin
* export to s3
  • Loading branch information
holuss authored Sep 23, 2024
1 parent ff132a5 commit 1b27502
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 3 deletions.
21 changes: 19 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ workflows:
only:
- main

publish-cli-workflow:
jobs:
- start-publish-cli:
type: approval
- publish-cli:
requires:
- start-publish-cli
commands:
build-release:
steps:
Expand Down Expand Up @@ -103,7 +110,7 @@ jobs:
key: jars-{{ checksum "build.gradle" }}
- run-tests

# ------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
publish-snapshot:
executor: java-executor
steps:
Expand All @@ -119,9 +126,9 @@ jobs:
steps:
- checkout
- build-release
- build-cli
- run-tests
- setup-aws-credentials
- build-cli
- deploy:
name: Upload libraries to Mapbox SDK Registry
command: |
Expand All @@ -144,3 +151,13 @@ jobs:
git remote set-url origin "https://x-access-token:[email protected]/mapbox/mapbox-java.git"
git config --global user.email [email protected] && git config --global user.name mapbox-ci
./scripts/publish_api_docs_android.sh -p $GITHUB_WRITER_TOKEN -t $CIRCLE_TAG
publish-cli:
executor: java-executor
steps:
- checkout
- setup-aws-credentials
- build-cli
- run:
name: 'Upload cli to S3 in: mapbox-java/services-cli.jar'
command: aws s3 cp services-cli/build/libs/services-cli.jar s3://utility-234858372212-us-east-1/mapbox-java/services-cli.jar
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ object MapboxJavaCli {
private const val COMMAND_HELP = "h"
private const val COMMAND_FILE_INPUT = "f"
private const val COMMAND_JSON_INPUT = "j"
private const val COMMAND_STDIN_INPUT = "s"
private const val COMMAND_PRETTY_PRINT = "p"
private const val COMMAND_FAIL_ON_CONVERT_BACK = "c"

Expand All @@ -45,7 +46,16 @@ object MapboxJavaCli {
.longOpt("json")
.hasArg(true)
.desc("String containing the json. Instead of providing files it " +
"is possible to relay the json directly.")
"is possible to relay on the json directly.")
.required(false)
.build()
)
.addOption(
Option.builder(COMMAND_STDIN_INPUT)
.longOpt("stdin")
.hasArg(false)
.desc("Stream redirection to the executable instead of file or " +
"string.")
.required(false)
.build()
)
Expand Down Expand Up @@ -97,6 +107,10 @@ object MapboxJavaCli {
val fileInput = commandLine.getOptionValue(COMMAND_FILE_INPUT)
results.addAll(directionsResponseValidator.parseFile(fileInput))
}

commandLine.hasOption(COMMAND_STDIN_INPUT) -> {
results.add(directionsResponseValidator.parseStdin())
}
}

val failure = !results.all { it.success } ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.mapbox.services.cli.validator

import com.mapbox.api.directions.v5.models.DirectionsResponse
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.util.stream.Collectors
import kotlin.text.Charsets.UTF_8

/**
Expand Down Expand Up @@ -30,6 +33,16 @@ class DirectionsResponseValidator {
*/
fun parseJson(json: String): ValidatorResult = validateJson(json, ValidatorInput.Json)

/**
* Parses
* @return results parsed from the JSON
*/
fun parseStdin(): ValidatorResult {
val json: String = BufferedReader(InputStreamReader(System.`in`))
.lines().collect(Collectors.joining("\n"))
return validateJson(json, ValidatorInput.Stdin)
}

private fun File.forEachFile(function: (File) -> Unit) = walk()
.filter { !it.isDirectory }
.forEach(function)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data class ValidatorResult(
sealed class ValidatorInput {
data class File(val name: String) : ValidatorInput()
object Json : ValidatorInput()
object Stdin : ValidatorInput()

companion object {
fun gsonAdapter(): RuntimeTypeAdapterFactory<ValidatorInput> {
Expand All @@ -28,6 +29,10 @@ sealed class ValidatorInput {
Json::class.java,
Json::class.simpleName
)
.registerSubtype(
Stdin::class.java,
Stdin::class.simpleName
)
}
}
}
Expand Down

0 comments on commit 1b27502

Please sign in to comment.