mirror of
https://github.com/zu1k/nali.git
synced 2025-02-02 10:22:41 +08:00
move system related code to app
This commit is contained in:
parent
23ba5a45a5
commit
ac1ca3f661
18
cmd/cdn.go
18
cmd/cdn.go
@ -1,10 +1,6 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/zu1k/nali/internal/app"
|
"github.com/zu1k/nali/internal/app"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -21,19 +17,7 @@ var cdnCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
app.InitCDNDB()
|
app.InitCDNDB()
|
||||||
|
app.CDN(args)
|
||||||
if len(args) == 0 {
|
|
||||||
stdin := bufio.NewScanner(os.Stdin)
|
|
||||||
for stdin.Scan() {
|
|
||||||
line := stdin.Text()
|
|
||||||
if line == "quit" || line == "exit" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Println(app.ReplaceCDNInString(line))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
app.ParseCDNs(args)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
26
cmd/root.go
26
cmd/root.go
@ -1,18 +1,12 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/zu1k/nali/internal/app"
|
"github.com/zu1k/nali/internal/app"
|
||||||
"github.com/zu1k/nali/internal/ipdb"
|
"github.com/zu1k/nali/internal/ipdb"
|
||||||
"golang.org/x/text/encoding/simplifiedchinese"
|
|
||||||
"golang.org/x/text/transform"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@ -61,25 +55,7 @@ Find document on: https://github.com/zu1k/nali
|
|||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
app.InitIPDB(ipdb.GetIPDBType())
|
app.InitIPDB(ipdb.GetIPDBType())
|
||||||
app.InitCDNDB()
|
app.InitCDNDB()
|
||||||
|
app.Root(args)
|
||||||
if len(args) == 0 {
|
|
||||||
stdin := bufio.NewScanner(os.Stdin)
|
|
||||||
for stdin.Scan() {
|
|
||||||
line := stdin.Text()
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
ftype, _ := syscall.GetFileType(syscall.Handle(os.Stdin.Fd()))
|
|
||||||
if ftype == 3 {
|
|
||||||
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if line == "quit" || line == "exit" {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
fmt.Printf("%s\n", app.ReplaceIPInString(app.ReplaceCDNInString(line)))
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
app.ParseIPs(args)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
internal/app/command_others.go
Normal file
39
internal/app/command_others.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// +build !windows
|
||||||
|
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Root(args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
stdin := bufio.NewScanner(os.Stdin)
|
||||||
|
for stdin.Scan() {
|
||||||
|
line := stdin.Text()
|
||||||
|
if line == "quit" || line == "exit" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%s\n", ReplaceIPInString(ReplaceCDNInString(line)))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ParseIPs(args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CDN(args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
stdin := bufio.NewScanner(os.Stdin)
|
||||||
|
for stdin.Scan() {
|
||||||
|
line := stdin.Text()
|
||||||
|
if line == "quit" || line == "exit" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(ReplaceCDNInString(line))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ParseCDNs(args)
|
||||||
|
}
|
||||||
|
}
|
56
internal/app/command_windows.go
Normal file
56
internal/app/command_windows.go
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
|
"golang.org/x/text/encoding/simplifiedchinese"
|
||||||
|
"golang.org/x/text/transform"
|
||||||
|
)
|
||||||
|
|
||||||
|
var pipeline = false
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
ftype, _ := syscall.GetFileType(syscall.Handle(os.Stdin.Fd()))
|
||||||
|
pipeline = ftype == 3
|
||||||
|
}
|
||||||
|
|
||||||
|
func Root(args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
stdin := bufio.NewScanner(os.Stdin)
|
||||||
|
for stdin.Scan() {
|
||||||
|
line := stdin.Text()
|
||||||
|
if pipeline {
|
||||||
|
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
|
||||||
|
}
|
||||||
|
if line == "quit" || line == "exit" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Printf("%s\n", ReplaceIPInString(ReplaceCDNInString(line)))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ParseIPs(args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func CDN(args []string) {
|
||||||
|
if len(args) == 0 {
|
||||||
|
stdin := bufio.NewScanner(os.Stdin)
|
||||||
|
for stdin.Scan() {
|
||||||
|
line := stdin.Text()
|
||||||
|
if pipeline {
|
||||||
|
line, _, _ = transform.String(simplifiedchinese.GBK.NewDecoder(), line)
|
||||||
|
}
|
||||||
|
if line == "quit" || line == "exit" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Println(ReplaceCDNInString(line))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ParseCDNs(args)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user