1
0
mirror of https://github.com/zu1k/nali.git synced 2025-01-22 13:19:02 +08:00
nali/cmd/update.go

42 lines
1.1 KiB
Go
Raw Permalink Normal View History

2020-07-17 12:12:04 +08:00
package cmd
import (
"log"
2022-05-05 11:49:11 +08:00
"strings"
2020-07-17 12:12:04 +08:00
"github.com/zu1k/nali/internal/db"
"github.com/zu1k/nali/internal/repo"
2021-08-03 07:54:35 +08:00
"github.com/spf13/cobra"
2020-07-17 12:12:04 +08:00
)
// updateCmd represents the update command
var updateCmd = &cobra.Command{
Use: "update [--db dbs -v]",
Short: "update qqwry, zxipv6wry, ip2region ip database and cdn, update nali to latest version if -v",
Long: `update qqwry, zxipv6wry, ip2region ip database and cdn. Use commas to separate. update nali to latest version if -v`,
Example: "nali update --db qqwry,cdn -v",
2020-07-17 12:12:04 +08:00
Run: func(cmd *cobra.Command, args []string) {
2022-05-05 11:49:11 +08:00
DBs, _ := cmd.Flags().GetString("db")
version, _ := cmd.Flags().GetBool("v")
if version {
if err := repo.UpdateRepo(); err != nil {
log.Printf("update nali to latest version failed: %v \n", err)
}
}
2022-05-05 11:49:11 +08:00
var DBNameArray []string
if DBs != "" {
DBNameArray = strings.Split(DBs, ",")
}
db.UpdateDB(DBNameArray...)
2020-07-17 12:12:04 +08:00
},
}
func init() {
2023-01-08 09:55:06 +08:00
updateCmd.PersistentFlags().String("db", "", "choose db you want to update")
updateCmd.PersistentFlags().Bool("v", false, "decide whether to update the nali version")
2020-07-17 12:12:04 +08:00
rootCmd.AddCommand(updateCmd)
}