Skip to content

Commit

Permalink
documents ip command
Browse files Browse the repository at this point in the history
  • Loading branch information
martinusso committed Jan 12, 2020
1 parent f0b18f8 commit eb4d070
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,29 @@ BRL: 4.05 (USD 0.25), EUR: 0.90 (USD 1.12), GBP: 0.76 (USD 1.31)
-h, --help help for exchange
```

### ip

IP geolocation.
It provides a simple IP to country, state and city mapping. Using db-ip.com/api.

_Copies automatically the output to the clipboard._

##### Usage:

```
~ zx ip 8.8.8.8
IP: 8.8.8.8
Continent: (SA) South America
Country: (BR) Brazil
City: Vitória (Espírito Santo)
```

##### Flags:
```
-h, --help help for ip
```


### jwt

Decode a JWT token.
Expand Down
12 changes: 5 additions & 7 deletions cmd/ip.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"fmt"

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

var (
inputIP string
ipURL = "https://api.db-ip.com/v2/free"
ipURL = "https://api.db-ip.com/v2/free"

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

func init() {
ipCmd.Flags().StringVar(&inputIP, "ip", "", "IP")
rootCmd.AddCommand(ipCmd)
}

func runIP(args []string) (string, error) {
if inputIP == "" {
if len(args) > 0 {
inputIP = args[0]
}
if len(args) != 1 {
return "", errors.New(emptyInput)
}
inputIP := args[0]

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

Expand Down

0 comments on commit eb4d070

Please sign in to comment.