This commit is contained in:
zu1k 2023-01-08 09:55:06 +08:00
parent a77165b014
commit 8aebd93126
No known key found for this signature in database
GPG Key ID: 6CDDC150ABF9C46D
3 changed files with 46 additions and 1 deletions

31
cmd/info.go Normal file
View File

@ -0,0 +1,31 @@
package cmd
import (
"fmt"
"github.com/zu1k/nali/internal/constant"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// infoCmd represents the info command
var infoCmd = &cobra.Command{
Use: "info",
Short: "get the necessary information of nali",
Long: `get the necessary information of nali`,
Example: "nali info",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Nali Version: ", constant.Version)
fmt.Println("Config Dir Path: ", constant.ConfigDirPath)
fmt.Println("DB Data Dir Path: ", constant.DataDirPath)
fmt.Println("Selected IPv4 DB: ", viper.GetString("selected.ipv4"))
fmt.Println("Selected IPv6 DB: ", viper.GetString("selected.ipv6"))
fmt.Println("Selected CDN DB: ", viper.GetString("selected.cdn"))
},
}
func init() {
rootCmd.AddCommand(infoCmd)
}

View File

@ -25,6 +25,6 @@ var updateCmd = &cobra.Command{
}
func init() {
updateCmd.PersistentFlags().String("db", "", "choose db you want to update")
rootCmd.AddCommand(updateCmd)
rootCmd.PersistentFlags().String("db", "", "choose db you want to update")
}

View File

@ -14,6 +14,20 @@ func migration2v6() {
return
}
oldDefaultWorkPath := filepath.Join(homeDir, ".nali")
oldDefaultWorkPath, err = filepath.Abs(oldDefaultWorkPath)
if err != nil {
log.Errorf("Get absolute path for oldDefaultWorkPath failed: %s\n", err)
}
mewWorkPath, err := filepath.Abs(constant.ConfigDirPath)
if err != nil {
log.Errorf("Get absolute path for mewWorkPath failed: %s\n", err)
}
if oldDefaultWorkPath == mewWorkPath {
// User chooses to continue using old directory
return
}
_, err = os.Stat(oldDefaultWorkPath)
if err == nil {
println("Old data directories are detected and will attempt to migrate automatically")