-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroot.go
72 lines (50 loc) · 1.2 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package cmd
import (
"log"
"os"
"github.com/spf13/cobra"
"github.com/zu1k/nali/internal/app"
"github.com/zu1k/nali/internal/constant"
)
var rootCmd = &cobra.Command{
Use: "nali",
Short: "An offline tool for querying IP geographic information",
Long: `An offline tool for querying IP geographic information.
Find document on: https://github.com/zu1k/nali
#1 Query a simple IP address
$ nali 1.2.3.4
or use pipe
$ echo IP 6.6.6.6 | nali
#2 Query multiple IP addresses
$ nali 1.2.3.4 4.3.2.1 123.23.3.0
#3 Interactive query
$ nali
123.23.23.23
123.23.23.23 [越南 越南邮电集团公司]
quit
#4 Use with dig
$ dig nali.lgf.im +short | nali
#5 Use with nslookup
$ nslookup nali.lgf.im 8.8.8.8 | nali
#6 Use with any other program
bash abc.sh | nali
#7 IPV6 support
$ nslookup google.com | nali
`,
Version: constant.Version,
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
gbk, _ := cmd.Flags().GetBool("gbk")
app.Root(args, gbk)
},
}
// Execute parse subcommand and run
func Execute() {
if err := rootCmd.Execute(); err != nil {
log.Fatal(err.Error())
os.Exit(1)
}
}
func init() {
rootCmd.Flags().Bool("gbk", false, "Use GBK decoder")
}