diff --git a/cmd/info.go b/cmd/info.go new file mode 100644 index 0000000..86fc633 --- /dev/null +++ b/cmd/info.go @@ -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) +} diff --git a/cmd/update.go b/cmd/update.go index 28cbd67..d60013e 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -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") } diff --git a/internal/migration/v6.go b/internal/migration/v6.go index 4fa0510..94662bd 100644 --- a/internal/migration/v6.go +++ b/internal/migration/v6.go @@ -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")