mirror of
https://github.com/QuilibriumNetwork/ceremonyclient.git
synced 2026-02-25 20:37:27 +08:00
71 lines
2.0 KiB
Go
71 lines
2.0 KiB
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/cobra"
|
|
clientNode "source.quilibrium.com/quilibrium/monorepo/client/cmd/node"
|
|
"source.quilibrium.com/quilibrium/monorepo/client/utils"
|
|
)
|
|
|
|
var importCmd = &cobra.Command{
|
|
Use: "import [name] [source_directory]",
|
|
Short: "Import config.yml and keys.yml from a source directory",
|
|
Long: `Import config.yml and keys.yml from a source directory to the QuilibriumRoot config folder.
|
|
|
|
Example:
|
|
qclient node config import mynode /path/to/source
|
|
|
|
This will copy config.yml and keys.yml from /path/to/source to /home/quilibrium/configs/mynode/`,
|
|
Args: cobra.ExactArgs(2),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
name := args[0]
|
|
sourceDir := args[1]
|
|
|
|
// Check if source directory exists
|
|
if _, err := os.Stat(sourceDir); os.IsNotExist(err) {
|
|
fmt.Printf("Source directory does not exist: %s\n", sourceDir)
|
|
os.Exit(1)
|
|
}
|
|
|
|
if !HasConfigFiles(sourceDir) {
|
|
fmt.Printf("Source directory does not contain both config.yml and keys.yml files: %s\n", sourceDir)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Create target directory in the standard location
|
|
targetDir := filepath.Join(clientNode.ConfigDirs, name)
|
|
if err := os.MkdirAll(targetDir, 0755); err != nil {
|
|
fmt.Printf("Failed to create target directory: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Define source file paths
|
|
sourceConfigPath := filepath.Join(sourceDir, "config.yml")
|
|
sourceKeysPath := filepath.Join(sourceDir, "keys.yml")
|
|
|
|
// Copy config.yml
|
|
targetConfigPath := filepath.Join(targetDir, "config.yml")
|
|
if err := utils.CopyFile(sourceConfigPath, targetConfigPath); err != nil {
|
|
fmt.Printf("Failed to copy config.yml: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Copy keys.yml
|
|
targetKeysPath := filepath.Join(targetDir, "keys.yml")
|
|
if err := utils.CopyFile(sourceKeysPath, targetKeysPath); err != nil {
|
|
fmt.Printf("Failed to copy keys.yml: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
fmt.Printf("Successfully imported config files to %s\n", targetDir)
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
// Add the import command to the config command
|
|
ConfigCmd.AddCommand(importCmd)
|
|
}
|