Skip to content

Commit 57490d7

Browse files
committed
Update default to not stay open, fixes #16
1 parent 93ef2ca commit 57490d7

File tree

2 files changed

+51
-36
lines changed

2 files changed

+51
-36
lines changed

CoreLocationCLI/main.swift

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Contacts
1313
class Delegate: NSObject, CLLocationManagerDelegate {
1414
let geoCoder = CLGeocoder()
1515
let locationManager = CLLocationManager()
16-
var once = false
16+
var follow = false
1717
var verbose = false
1818
var format = "%latitude %longitude"
1919
var exitAtTimeout = true
@@ -55,10 +55,9 @@ class Delegate: NSObject, CLLocationManagerDelegate {
5555
output = output.replacingOccurrences(of: "%address", with: address)
5656
}
5757
print(output)
58-
if self.once {
58+
if !self.follow {
5959
exit(0)
6060
}
61-
6261
}
6362

6463
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
@@ -115,7 +114,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
115114
print("OPTIONS:")
116115
print(" -h Display this help message and exit")
117116
print("")
118-
print(" -once YES Print one location and exit")
117+
print(" -follow YES Continually print location")
119118
print(" -verbose YES Verbose mode")
120119
print(" -format 'format' Print a formatted string with the following specifiers")
121120
print(" %%latitude Latitude (degrees north; or negative for south")
@@ -128,7 +127,7 @@ class Delegate: NSObject, CLLocationManagerDelegate {
128127
print(" %%time Time")
129128
print(" %%address Reverse geocoded location to an address")
130129
print(" -json Prints a JSON object with all information available")
131-
print(" Also implies -once")
130+
print(" Also disables -follow")
132131
print("")
133132
print(" Default format if unspecified is: %%latitude %%longitude")
134133
print("")
@@ -141,16 +140,16 @@ for (i, argument) in ProcessInfo().arguments.enumerated() {
141140
case "-h":
142141
delegate.help()
143142
exit(0)
144-
case "-once":
145-
delegate.once = true
143+
case "-follow":
144+
delegate.follow = true
146145
case "-verbose":
147146
delegate.verbose = true
148147
case "-format":
149148
if ProcessInfo().arguments.count > i+1 {
150149
delegate.format = ProcessInfo().arguments[i+1]
151150
}
152151
case "-json":
153-
delegate.once = true
152+
delegate.follow = false
154153
delegate.format = "{"
155154
delegate.format.append("\n \"latitude\": %latitude")
156155
delegate.format.append("\n \"longitude\": %longitude")

README.md

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CoreLocationCLI
22

3-
CoreLocationCLI gets the physical location of your device and prints it to standard output. If you move it will also print out your updated location. *Kill it with CTRL-C.*
3+
CoreLocationCLI gets the physical location of your device and prints it to standard output. If you move it can also print your updated location. *Kill it with CTRL-C.*
44

55
![Usage](https://cloud.githubusercontent.com/assets/382183/25063655/52c11234-221d-11e7-81fb-0f8712dac393.gif)
66

@@ -10,56 +10,72 @@ Note for Mac users: make sure WiFi is turned on. Otherwise you will see `kCLErro
1010

1111
```sh
1212
CoreLocationCLI -h
13-
CoreLocationCLI [-once] -json
14-
CoreLocationCLI [-once] [-verbose] [-format FORMAT]
13+
CoreLocationCLI -json
14+
CoreLocationCLI [-follow] [-verbose] [-format FORMAT]
1515
```
1616

17-
| Switch | Description |
18-
| ---------------- | ------------------------------------------------------ |
19-
| `-h` | Display this help message and exit |
20-
| `-once` | Print one location and exit |
21-
| `-verbose` | Verbose mode |
22-
| `-json` | JSON output mode |
17+
| Switch | Description |
18+
| ---------------- | ---------------------------------------- |
19+
| `-h` | Display this help message and exit |
20+
| `-follow` | Continually print location |
21+
| `-verbose` | Verbose mode |
22+
| `-json` | JSON output mode |
2323
| `-format FORMAT` | Print a formatted string with the following specifiers |
2424

25-
| Format | Description |
26-
| -------------- | ---------------------------------------------- |
25+
| Format | Description |
26+
| -------------- | ---------------------------------------- |
2727
| `%%latitude` | Latitude (degrees north; or negative for south |
28-
| `%%longitude` | Longitude (degrees west; or negative for east |
29-
| `%%altitude` | Altitude (meters) |
30-
| `%%direction` | Degrees from true north |
31-
| `%%speed` | Meters per second |
32-
| `%%h_accuracy` | Horizontal accuracy (meters) |
33-
| `%%v_accuracy` | Vertical accuracy (meters) |
34-
| `%%time` | Time |
35-
| `%%address` | Reverse geocoded location to an address |
28+
| `%%longitude` | Longitude (degrees west; or negative for east |
29+
| `%%altitude` | Altitude (meters) |
30+
| `%%direction` | Degrees from true north |
31+
| `%%speed` | Meters per second |
32+
| `%%h_accuracy` | Horizontal accuracy (meters) |
33+
| `%%v_accuracy` | Vertical accuracy (meters) |
34+
| `%%time` | Time |
35+
| `%%address` | Reverse geocoded location to an address |
3636

37-
The default format if unspecified is: `%%latitude %%longitude`.
37+
The default format is: `%%latitude %%longitude`.
3838

3939
# Output examples
4040

4141
```sh
4242
./CoreLocationCLI
4343
```
4444

45+
> ```
4546
> 50.943829 6.941043
47+
> ```
4648
4749
```sh
48-
./CoreLocationCLI -once yes -format "%latitude %longitude\n%address"
50+
./CoreLocationCLI -format "%latitude %longitude\n%address"
4951
```
5052
51-
50.943829 6.941043
52-
Kaiser-Wilhelm-Ring 21
53-
Cologne North Rhine-Westphalia 50672
54-
Germany
53+
> ```
54+
> 50.943829 6.941043
55+
> Kaiser-Wilhelm-Ring 21
56+
> Cologne North Rhine-Westphalia 50672
57+
> Germany
58+
> ```
5559
5660
```sh
5761
./CoreLocationCLI -json
5862
```
5963
60-
```json
61-
{"latitude":40.124159, "longitude":-75.036274}
62-
```
64+
>```json
65+
>{
66+
> "latitude": 40.141196
67+
> "longitude": -75.034815
68+
> "altitude": 92.00
69+
> "direction": -1.0
70+
> "speed": -1
71+
> "h_accuracy": 65
72+
> "v_accuracy": 10
73+
> "time": "2017-06-25 05:29:38 +0000"
74+
> "address": "407 Keats Rd
75+
>Lower Moreland PA 19006
76+
>United States"
77+
>}
78+
>```
6379
6480
# Installation
6581

0 commit comments

Comments
 (0)