1
0
mirror of https://github.com/zu1k/nali.git synced 2025-03-11 19:02:03 +08:00
nali/cmd/update.go
2023-09-28 22:41:43 +08:00

38 lines
906 B
Go

package cmd
import (
"log"
"strings"
"github.com/zu1k/nali/internal/db"
"github.com/zu1k/nali/internal/repo"
"github.com/spf13/cobra"
)
// updateCmd represents the update command
var updateCmd = &cobra.Command{
Use: "update [--db dbs]",
Short: "update qqwry, zxipv6wry, ip2region ip database and cdn",
Long: `update qqwry, zxipv6wry, ip2region ip database and cdn. Use commas to separate`,
Example: "nali update --db qqwry,cdn",
Run: func(cmd *cobra.Command, args []string) {
DBs, _ := cmd.Flags().GetString("db")
if err := repo.UpdateRepo(); err != nil {
log.Printf("update nali to latest version failed: %v \n", err)
}
var DBNameArray []string
if DBs != "" {
DBNameArray = strings.Split(DBs, ",")
}
db.UpdateDB(DBNameArray...)
},
}
func init() {
updateCmd.PersistentFlags().String("db", "", "choose db you want to update")
rootCmd.AddCommand(updateCmd)
}