mirror of
https://github.com/luxfi/cli.git
synced 2026-10-30 17:01:20 +00:00
- Update github.com/luxfi/netrunner v1.15.3 → v1.15.4 - Update github.com/luxfi/node v1.22.77 → v1.22.80 - Remove local replace directive for netrunner - Use published package versions for reproducible builds
65 lines
1.6 KiB
Go
65 lines
1.6 KiB
Go
// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package chaincmd
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
|
|
"github.com/luxfi/cli/pkg/prompts"
|
|
"github.com/luxfi/cli/pkg/safety"
|
|
"github.com/luxfi/cli/pkg/ux"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var forceDelete bool
|
|
|
|
func newDeleteCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "delete [chainName]",
|
|
Short: "Delete a blockchain configuration",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: deleteChain,
|
|
}
|
|
|
|
cmd.Flags().BoolVarP(&forceDelete, "force", "f", false, "Skip confirmation prompt (required in non-interactive mode)")
|
|
return cmd
|
|
}
|
|
|
|
func deleteChain(cmd *cobra.Command, args []string) error {
|
|
chainName := args[0]
|
|
|
|
// Basic validation (detailed validation in safety package)
|
|
if chainName == "" || filepath.Base(chainName) != chainName {
|
|
return fmt.Errorf("invalid chain name: %s", chainName)
|
|
}
|
|
|
|
if !app.ChainConfigExists(chainName) {
|
|
return fmt.Errorf("chain %s not found", chainName)
|
|
}
|
|
|
|
if !forceDelete {
|
|
// In non-interactive mode, require --force flag
|
|
if !prompts.IsInteractive() {
|
|
return fmt.Errorf("confirmation required: use --force to delete without confirmation")
|
|
}
|
|
confirm, err := app.Prompt.CaptureYesNo(fmt.Sprintf("Delete chain %s?", chainName))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if !confirm {
|
|
ux.Logger.PrintToUser("Cancelled")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// Use safety package for protected path deletion
|
|
if err := safety.RemoveChainConfig(app.GetBaseDir(), chainName); err != nil {
|
|
return fmt.Errorf("failed to delete chain: %w", err)
|
|
}
|
|
|
|
ux.Logger.PrintToUser("Deleted chain %s", chainName)
|
|
return nil
|
|
}
|