-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from fummicc1/feature/cli
Add command line tool.
- Loading branch information
Showing
5 changed files
with
243 additions
and
21 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
.swiftpm/xcode/xcshareddata/xcschemes/GeoHash-Package.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1610" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "GeoHashFramework" | ||
BuildableName = "GeoHashFramework" | ||
BlueprintName = "GeoHashFramework" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "geohash" | ||
BuildableName = "geohash" | ||
BlueprintName = "geohash" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "GeoHashFrameworkTests" | ||
BuildableName = "GeoHashFrameworkTests" | ||
BlueprintName = "GeoHashFrameworkTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "geohash" | ||
BuildableName = "geohash" | ||
BlueprintName = "geohash" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "geohash" | ||
BuildableName = "geohash" | ||
BlueprintName = "geohash" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"originHash" : "cd9ca0ea0320522c8fe77ddafee840264ac5a469caedc78393244502d02dd387", | ||
"pins" : [ | ||
{ | ||
"identity" : "swift-argument-parser", | ||
"kind" : "remoteSourceControl", | ||
"location" : "https://github.com/apple/swift-argument-parser", | ||
"state" : { | ||
"revision" : "41982a3656a71c768319979febd796c6fd111d5c", | ||
"version" : "1.5.0" | ||
} | ||
} | ||
], | ||
"version" : 3 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// GeoHashCLI.swift | ||
// GeoHashCLI | ||
// | ||
// Created by Fumiya Tanaka on 2024/11/17. | ||
// | ||
|
||
import ArgumentParser | ||
import GeoHashFramework | ||
|
||
@main | ||
struct GeoHashCLI: ParsableCommand { | ||
|
||
@Option(name: .shortAndLong, help: "length of GeoHash") | ||
var length: Int = 8 | ||
|
||
@Argument(help: "latitude of coordinate") | ||
var latitude: Double? | ||
|
||
@Argument(help: "longitude of coordinate") | ||
var longitude: Double? | ||
|
||
@Option(help: "concatenated coordinate formatted as latitude,longitude") | ||
var coordinate: String? | ||
|
||
mutating func run() throws { | ||
precondition( | ||
(latitude != nil && longitude != nil) || coordinate != nil | ||
) | ||
let precision = GeoHashBitsPrecision.exact(digits: length * 5) | ||
|
||
let geoHash: GeoHash | ||
|
||
if let coordinate { | ||
let components = coordinate.split(separator: ",") | ||
guard components.count == 2 else { | ||
throw ValidationError("Coordinate must be formatted as latitude,longitude") | ||
} | ||
latitude = Double(components[0]) | ||
longitude = Double(components[1]) | ||
|
||
geoHash = .init( | ||
latitude: latitude!, | ||
longitude: longitude!, | ||
precision: precision | ||
) | ||
} else if let latitude, let longitude { | ||
geoHash = .init( | ||
latitude: latitude, | ||
longitude: longitude, | ||
precision: precision | ||
) | ||
} else { | ||
throw ValidationError("Coordinate or latitude and longitude must be provided.") | ||
} | ||
print(geoHash.geoHash) | ||
} | ||
} |