ceremonyclient/client/cmd/node/nodeconfig/switch.go
Tyler Sturos 9cfbdef12c
Feat/2.1 qclient refactor and node install (#429)
* initial auto-update

* working link, update, and testing docker container and scripts

* refactor packages/folders

* move files to proper folders

* fix typos

Closes #421

* optimize rpm imports

* optimize channel imports

* Refactor split command to allow testing of split operations

Closes #338

* modify split and test for folder changes

* remove alias

* fix docker warning about FROM and AS being in different letter case

Closes #422

* QClient Account Command

* Display transaction details and confirmation prompts for transfer and merge commands

* build qclient docker improvements

* update build args for mpfr.so.6

* update install and node commands

* remove NodeConfig check for qclient node commands

* udpate

* working node commands

* update commands

* move utils and rename package

---------

Co-authored-by: Vasyl Tretiakov <vasyl.tretiakov@gmail.com>
Co-authored-by: littleblackcloud <163544315+littleblackcloud@users.noreply.github.com>
Co-authored-by: 0xOzgur <29779769+0xOzgur@users.noreply.github.com>
Co-authored-by: Cassandra Heart <7929478+CassOnMars@users.noreply.github.com>
2025-04-11 21:43:20 -05:00

83 lines
2.2 KiB
Go

package nodeconfig
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"source.quilibrium.com/quilibrium/monorepo/client/utils"
)
var SwitchConfigCmd = &cobra.Command{
Use: "switch [name]",
Short: "Switch the config to be run by the node",
Long: fmt.Sprintf(`Switch the configuration to be run by the node by creating a symlink.
Example:
qclient node config switch mynode
This will symlink %s/mynode to %s`, ConfigDirs, NodeConfigToRun),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
var name string
if len(args) > 0 {
name = args[0]
} else {
// List available configurations
configs, err := ListConfigurations()
if err != nil {
fmt.Printf("Error listing configurations: %s\n", err)
os.Exit(1)
}
if len(configs) == 0 {
fmt.Println("No configurations found. Create one with 'qclient node config create'")
os.Exit(1)
}
fmt.Println("Available configurations:")
for i, config := range configs {
fmt.Printf("%d. %s\n", i+1, config)
}
// Prompt for choice
var choice int
fmt.Print("Enter the number of the configuration to set as default: ")
_, err = fmt.Scanf("%d", &choice)
if err != nil || choice < 1 || choice > len(configs) {
fmt.Println("Invalid choice. Please enter a valid number.")
os.Exit(1)
}
name = configs[choice-1]
}
// Construct the source directory path
sourceDir := filepath.Join(ConfigDirs, name)
// Check if source directory exists
if _, err := os.Stat(sourceDir); os.IsNotExist(err) {
fmt.Printf("Config directory does not exist: %s\n", sourceDir)
os.Exit(1)
}
// Check if the source directory has both config.yml and keys.yml files
if !HasConfigFiles(sourceDir) {
fmt.Printf("Source directory does not contain both config.yml and keys.yml files: %s\n", sourceDir)
os.Exit(1)
}
// Construct the default directory path
defaultDir := filepath.Join(ConfigDirs, "default")
// Create the symlink
if err := utils.CreateSymlink(sourceDir, defaultDir); err != nil {
fmt.Printf("Failed to create symlink: %s\n", err)
os.Exit(1)
}
fmt.Printf("Successfully set %s as the default configuration\n", name)
},
}