diff --git a/CHANGELOG.md b/CHANGELOG.md index 851c247e1..ad1df2f12 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,20 @@ ## 2.7.0 +### Packaging + * Xcode 13.0 or above and Swift 5.5 or above are now required to build MapboxDirections from source. ([#725](https://github.com/mapbox/mapbox-directions-swift/pull/725), [#727](https://github.com/mapbox/mapbox-directions-swift/pull/727)) + +### Command line tool + +* Removed the `--config` option. Instead, pass in either the path to a JSON configuration file or the full URL to a Mapbox Directions API or Mapbox Map Matching API request. ([#726](https://github.com/mapbox/mapbox-directions-swift/pull/726)) +* When the `MAPBOX_ACCESS_TOKEN` environment variable is unset, the tool exits with an error code instead of crashing. ([#728](https://github.com/mapbox/mapbox-directions-swift/pull/728)) +* The tool now connects to the API endpoint in the `MAPBOX_HOST` environment variable, if specified. ([#728](https://github.com/mapbox/mapbox-directions-swift/pull/728)) + +### Other changes + * Added `Waypoint.allowsSnappingToStaticallyClosedRoad` property to allow snapping the waypoint’s location to a statically (long-term) closed part of a road. ([#721](https://github.com/mapbox/mapbox-directions-swift/pull/721)) * `RouteOptions(url:)` now returns `nil` if given a Mapbox Map Matching API request URL, and `MatchOptions(url:)` returns `nil` if given a Mapbox Directions API request URL. ([#728](https://github.com/mapbox/mapbox-directions-swift/pull/728)) -* When the `MAPBOX_ACCESS_TOKEN` environment variable is unset, the `mapbox-directions-swift` command line tool exits with an error code instead of crashing. ([#728](https://github.com/mapbox/mapbox-directions-swift/pull/728)) -* The `mapbox-directions-swift` command line tool now connects to the API endpoint in the `MAPBOX_HOST` environment variable, if specified. ([#728](https://github.com/mapbox/mapbox-directions-swift/pull/728)) ## v2.6.0 diff --git a/CommandLineTool.md b/CommandLineTool.md index cf85b0d6a..aff9a284e 100644 --- a/CommandLineTool.md +++ b/CommandLineTool.md @@ -23,12 +23,16 @@ To connect to an API endpoint other than the default Mapbox API endpoint, set th `mapbox-directions-swift` is a useful tool for mobile quality assurance. This tool can be used to verify a response to ensure proper Directions API integration, get a [GPX](https://wikipedia.org/wiki/GPS_Exchange_Format) trace that can be used in the Xcode Simulator, and convert a Directions API request to an Options object. +### Arguments + +The sole argument is either: + +* The path to a JSON file that contains a serialized `RouteOptions` or `MatchOptions` +* The URL of a Mapbox Directions API or Mapbox Map Matching API request + ### Options `--input` -An optional flag for the filepath to the input JSON. If this flag is not used, `mapbox-directions-swift` will fallback to a Directions API request. To request using specific coordinates, specify coordinates using `--waypoints` or a Directions API request using `--url`. - -`--config` -An optional flag for the filepath to the JSON, containing serialized Options data. +An optional flag for the filepath to the input JSON. If this flag is not used, `mapbox-directions-swift` will fallback to a Directions API request. `--output` An optional flag for the filepath to save the conversion result. If no filepath is provided, the result will output to the shell. If you want a GPX trace that can be easily uploaded to Xcode, provide an output filepath with this flag. diff --git a/Sources/MapboxDirectionsCLI/CodingOperation.swift b/Sources/MapboxDirectionsCLI/CodingOperation.swift index 058cae394..e5b48a272 100644 --- a/Sources/MapboxDirectionsCLI/CodingOperation.swift +++ b/Sources/MapboxDirectionsCLI/CodingOperation.swift @@ -118,13 +118,17 @@ class CodingOperation (Data) { + private func response(fetching directionsOptions: OptionsType) -> (Data) { + let directions = Directions(credentials: credentials) + let url = directions.url(forCalculating: directionsOptions) + return response(fetching: url) + } + + private func response(fetching url: URL) -> Data { let semaphore = DispatchSemaphore(value: 0) var responseData: Data! - let directions = Directions(credentials: credentials) - let url = directions.url(forCalculating: directionsOptions) let urlSession = URLSession(configuration: .ephemeral) let task = urlSession.dataTask(with: url) { (data, response, error) in @@ -151,20 +155,43 @@ class CodingOperation