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

Add command line interface #1198

Merged
merged 1 commit into from
Oct 6, 2020
Merged

Add command line interface #1198

merged 1 commit into from
Oct 6, 2020

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Oct 1, 2020

Resolves https://github.com/mapbox/navigation-sdks/issues/542

Usage

  1. build
➜  mapbox-java git:(km-services-cli) ./gradlew shadowJar
or
➜  mapbox-java git:(km-services-cli) make build-cli
  1. commands
➜  mapbox-java git:(km-services-cli) java -jar services-cli/build/libs/services-cli-all.jar
Missing required option: f
usage: java -jar services-cli/build/libs/mapboxjava-cli.jar
 -f,--file <arg>   Path to a json file or directory
 -h,--help         Show command line interface usage
  1. validate json
➜  mapbox-java git:(km-services-cli) java -jar services-cli/build/libs/services-cli-all.jar -f services-directions/src/test/resources/directions_v5_waypoint_names.json
[{"filename":"directions_v5_waypoint_names.json","success":true,"converts_back":false}]

Alternatives

The original ticket asks to test json on any previous build of mapbox-java, which is a little complicated with gradle - so here was an alternative to make the CLI in NodeJs #1189 - This approach was closed because we would rather build it in kotlin.

Next steps

Distributing
We will want to add this jar to our mapbox-java releases as an asset. Notice how classyshark does this too. This task is to make it so directions api can use them in their CI process.

Features
Currently you can make directions api calls with make commands using curl. This project will allow us to move those commands to use the actual mapbox-java implementation (it's not implemented yet, but this project is set up to hopefully make it easy to do so)

Feel free to add your ideas! This is also written in kotlin, so it will be easier to start building our mapbox-java modules in kotlin.

@kmadsen
Copy link
Contributor Author

kmadsen commented Oct 1, 2020

@kmadsen kmadsen force-pushed the km-services-cli branch 9 times, most recently from 905c44c to c0cb3ff Compare October 1, 2020 15:24
@zugaldia
Copy link
Member

zugaldia commented Oct 2, 2020

This is great @kmadsen - I just gave it a try, no issues. A few random suggestions, in no particular order, some of them could be tracked as tailwork:

  1. In addition to validating a JSON, it'd be good if we could set an arbitrary endpoint and execute an actual request like you mention in OP. That way, we could validate, for example, staging endpoints.
  2. There's a handy Gradle plugin called shadow that creates "fat jars". It combines a project's dependency classes and resources into a single output jar. This makes the jar heavier, but self-contained.
  3. Building on the item above, I'd document the process to attach the resulting jar with every release.

@kmadsen
Copy link
Contributor Author

kmadsen commented Oct 2, 2020

  1. use shadowJar

Yea thanks for the reminder! removes the TODO because they already solved the problems I was dealing with. it's all updated

  1. That way, we could validate, for example, staging endpoints

Yep agree but as tailwork 👍 ; was planning on making that another change so it can receive separate code review

  1. I'd document the process to attach the resulting jar with every release.

Tailwork agree 👍 ; Would like to dig in to see if we can make it more automated than documented

@kmadsen kmadsen force-pushed the km-services-cli branch 2 times, most recently from 42601e3 to 334da52 Compare October 5, 2020 16:36
Copy link
Contributor

@Guardiola31337 Guardiola31337 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work @kmadsen

Left a minor comment (not blocking the PR).

Another follow up would be creating a Gradle plugin that runs the MapboxJavaCli program.

Also don't forget to cut tickets with the tailwork listed in #1198 (comment)

services-cli/build.gradle Outdated Show resolved Hide resolved
@kmadsen kmadsen merged commit d45921d into master Oct 6, 2020
@kmadsen kmadsen deleted the km-services-cli branch October 6, 2020 17:08
Comment on lines +41 to +47
implementation("commons-cli:commons-cli:1.4")

// Kotlin
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")

// Testing
testImplementation("org.jetbrains.kotlin:kotlin-test-junit")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move these to gradle/dependencies.gradle #1198 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants