Skip to content

Commit eb4d070

Browse files
committed
documents ip command
1 parent f0b18f8 commit eb4d070

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,29 @@ BRL: 4.05 (USD 0.25), EUR: 0.90 (USD 1.12), GBP: 0.76 (USD 1.31)
164164
-h, --help help for exchange
165165
```
166166

167+
### ip
168+
169+
IP geolocation.
170+
It provides a simple IP to country, state and city mapping. Using db-ip.com/api.
171+
172+
_Copies automatically the output to the clipboard._
173+
174+
##### Usage:
175+
176+
```
177+
~ zx ip 8.8.8.8
178+
IP: 8.8.8.8
179+
Continent: (SA) South America
180+
Country: (BR) Brazil
181+
City: Vitória (Espírito Santo)
182+
```
183+
184+
##### Flags:
185+
```
186+
-h, --help help for ip
187+
```
188+
189+
167190
### jwt
168191

169192
Decode a JWT token.

cmd/ip.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"errors"
45
"fmt"
56

67
"github.com/martinusso/zx/internal/clipboard"
@@ -19,8 +20,7 @@ type ipResponse struct {
1920
}
2021

2122
var (
22-
inputIP string
23-
ipURL = "https://api.db-ip.com/v2/free"
23+
ipURL = "https://api.db-ip.com/v2/free"
2424

2525
ipCmd = &cobra.Command{
2626
Use: "ip",
@@ -40,16 +40,14 @@ It provides a simple IP to country, state and city mapping. Using db-ip.com/api.
4040
)
4141

4242
func init() {
43-
ipCmd.Flags().StringVar(&inputIP, "ip", "", "IP")
4443
rootCmd.AddCommand(ipCmd)
4544
}
4645

4746
func runIP(args []string) (string, error) {
48-
if inputIP == "" {
49-
if len(args) > 0 {
50-
inputIP = args[0]
51-
}
47+
if len(args) != 1 {
48+
return "", errors.New(emptyInput)
5249
}
50+
inputIP := args[0]
5351

5452
url := fmt.Sprintf("%s/%s", ipURL, inputIP)
5553

0 commit comments

Comments
 (0)