Files
draft/cmd/key.go
T
FernandoJVideira d7e4c554d8 chore: rename keystone to draft
Rename the module, CLI command name, and all references from
keystone/basalt to draft, and fix the stale build/README content
found along the way.
2026-08-25 13:55:24 +01:00

38 lines
769 B
Go

package cmd
import (
"fmt"
"github.com/spf13/cobra"
)
func init() {
newCmd.AddCommand(keyCmd)
}
var size int
var defaultSize = 32
var keyCmd = &cobra.Command{
Use: "key [size]",
Short: "Generate a new cryptographic key",
Long: `Generate a new cryptographic key for use in Draft projects.`,
Run: func(cmd *cobra.Command, args []string) {
var keyLength int
if cmd.Flags().Lookup("size").Changed {
keyLength = size
} else {
keyLength = defaultSize
}
if keyLength <= 32 {
fmt.Println("Warning: It is recommended to use a key size greater than 32 for better security.")
fmt.Println("Generating a key of default size:", defaultSize)
keyLength = defaultSize
}
key := randomString(keyLength)
println("Generated Key:", key)
},
}