2020-07-17 09:05:25 +08:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2020-07-17 10:52:36 +08:00
|
|
|
"bufio"
|
2020-07-17 09:05:25 +08:00
|
|
|
"fmt"
|
2020-07-17 09:41:09 +08:00
|
|
|
"log"
|
|
|
|
"os"
|
2020-07-17 09:05:25 +08:00
|
|
|
|
2020-07-17 12:12:04 +08:00
|
|
|
"github.com/zu1k/nali/internal/ipdb"
|
|
|
|
|
2020-07-17 09:05:25 +08:00
|
|
|
"github.com/zu1k/nali/internal/app"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
|
|
|
Use: "nali",
|
|
|
|
Short: "",
|
|
|
|
Long: ``,
|
2020-07-17 10:52:36 +08:00
|
|
|
Args: cobra.MinimumNArgs(0),
|
2020-07-17 09:05:25 +08:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2020-07-17 12:12:04 +08:00
|
|
|
app.InitIPDB(ipdb.GetIPDBType())
|
2020-07-17 09:05:25 +08:00
|
|
|
if len(args) == 0 {
|
2020-07-17 10:52:36 +08:00
|
|
|
stdin := bufio.NewScanner(os.Stdin)
|
|
|
|
for stdin.Scan() {
|
|
|
|
line := stdin.Text()
|
|
|
|
if line == "quit" || line == "exit" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(app.ReplaceInString(line))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
app.ParseIPs(args)
|
2020-07-17 09:05:25 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-07-17 09:55:24 +08:00
|
|
|
// Execute parse subcommand and run
|
2020-07-17 09:05:25 +08:00
|
|
|
func Execute() {
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
2020-07-17 09:41:09 +08:00
|
|
|
log.Fatal(err.Error())
|
|
|
|
os.Exit(1)
|
2020-07-17 09:05:25 +08:00
|
|
|
}
|
|
|
|
}
|