Skip to content

Commit 1b27502

Browse files
authored
[NAVAND-3174] Upgrade services-cli (#1593)
* handle input from Stdin * export to s3
1 parent ff132a5 commit 1b27502

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

.circleci/config.yml

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@ workflows:
3939
only:
4040
- main
4141

42+
publish-cli-workflow:
43+
jobs:
44+
- start-publish-cli:
45+
type: approval
46+
- publish-cli:
47+
requires:
48+
- start-publish-cli
4249
commands:
4350
build-release:
4451
steps:
@@ -103,7 +110,7 @@ jobs:
103110
key: jars-{{ checksum "build.gradle" }}
104111
- run-tests
105112

106-
# ------------------------------------------------------------------------------
113+
# ------------------------------------------------------------------------------
107114
publish-snapshot:
108115
executor: java-executor
109116
steps:
@@ -119,9 +126,9 @@ jobs:
119126
steps:
120127
- checkout
121128
- build-release
122-
- build-cli
123129
- run-tests
124130
- setup-aws-credentials
131+
- build-cli
125132
- deploy:
126133
name: Upload libraries to Mapbox SDK Registry
127134
command: |
@@ -144,3 +151,13 @@ jobs:
144151
git remote set-url origin "https://x-access-token:[email protected]/mapbox/mapbox-java.git"
145152
git config --global user.email [email protected] && git config --global user.name mapbox-ci
146153
./scripts/publish_api_docs_android.sh -p $GITHUB_WRITER_TOKEN -t $CIRCLE_TAG
154+
155+
publish-cli:
156+
executor: java-executor
157+
steps:
158+
- checkout
159+
- setup-aws-credentials
160+
- build-cli
161+
- run:
162+
name: 'Upload cli to S3 in: mapbox-java/services-cli.jar'
163+
command: aws s3 cp services-cli/build/libs/services-cli.jar s3://utility-234858372212-us-east-1/mapbox-java/services-cli.jar

services-cli/src/main/kotlin/com.mapbox.services.cli/MapboxJavaCli.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ object MapboxJavaCli {
1919
private const val COMMAND_HELP = "h"
2020
private const val COMMAND_FILE_INPUT = "f"
2121
private const val COMMAND_JSON_INPUT = "j"
22+
private const val COMMAND_STDIN_INPUT = "s"
2223
private const val COMMAND_PRETTY_PRINT = "p"
2324
private const val COMMAND_FAIL_ON_CONVERT_BACK = "c"
2425

@@ -45,7 +46,16 @@ object MapboxJavaCli {
4546
.longOpt("json")
4647
.hasArg(true)
4748
.desc("String containing the json. Instead of providing files it " +
48-
"is possible to relay the json directly.")
49+
"is possible to relay on the json directly.")
50+
.required(false)
51+
.build()
52+
)
53+
.addOption(
54+
Option.builder(COMMAND_STDIN_INPUT)
55+
.longOpt("stdin")
56+
.hasArg(false)
57+
.desc("Stream redirection to the executable instead of file or " +
58+
"string.")
4959
.required(false)
5060
.build()
5161
)
@@ -97,6 +107,10 @@ object MapboxJavaCli {
97107
val fileInput = commandLine.getOptionValue(COMMAND_FILE_INPUT)
98108
results.addAll(directionsResponseValidator.parseFile(fileInput))
99109
}
110+
111+
commandLine.hasOption(COMMAND_STDIN_INPUT) -> {
112+
results.add(directionsResponseValidator.parseStdin())
113+
}
100114
}
101115

102116
val failure = !results.all { it.success } ||

services-cli/src/main/kotlin/com/mapbox/services/cli/validator/DirectionsResponseValidator.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package com.mapbox.services.cli.validator
22

33
import com.mapbox.api.directions.v5.models.DirectionsResponse
4+
import java.io.BufferedReader
45
import java.io.File
6+
import java.io.InputStreamReader
7+
import java.util.stream.Collectors
58
import kotlin.text.Charsets.UTF_8
69

710
/**
@@ -30,6 +33,16 @@ class DirectionsResponseValidator {
3033
*/
3134
fun parseJson(json: String): ValidatorResult = validateJson(json, ValidatorInput.Json)
3235

36+
/**
37+
* Parses
38+
* @return results parsed from the JSON
39+
*/
40+
fun parseStdin(): ValidatorResult {
41+
val json: String = BufferedReader(InputStreamReader(System.`in`))
42+
.lines().collect(Collectors.joining("\n"))
43+
return validateJson(json, ValidatorInput.Stdin)
44+
}
45+
3346
private fun File.forEachFile(function: (File) -> Unit) = walk()
3447
.filter { !it.isDirectory }
3548
.forEach(function)

services-cli/src/main/kotlin/com/mapbox/services/cli/validator/ValidatorResult.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ data class ValidatorResult(
1515
sealed class ValidatorInput {
1616
data class File(val name: String) : ValidatorInput()
1717
object Json : ValidatorInput()
18+
object Stdin : ValidatorInput()
1819

1920
companion object {
2021
fun gsonAdapter(): RuntimeTypeAdapterFactory<ValidatorInput> {
@@ -28,6 +29,10 @@ sealed class ValidatorInput {
2829
Json::class.java,
2930
Json::class.simpleName
3031
)
32+
.registerSubtype(
33+
Stdin::class.java,
34+
Stdin::class.simpleName
35+
)
3136
}
3237
}
3338
}

0 commit comments

Comments
 (0)