Files
scratchbox/cmd/scratchbox/generate_key.go
T
2026-06-01 01:29:47 -05:00

33 lines
681 B
Go

package main
import (
"fmt"
"github.com/spf13/cobra"
"scratchbox/internal/config"
)
func newGenerateKeyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "generate-key",
Short: "Print a random base64 encryption key to stdout",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return writeEncryptionKey(cmd)
},
}
return cmd
}
func writeEncryptionKey(cmd *cobra.Command) error {
key, err := config.GenerateEncryptionKey()
if err != nil {
return fmt.Errorf("generate encryption key: %w", err)
}
if _, err := fmt.Fprintln(cmd.OutOrStdout(), key); err != nil {
return fmt.Errorf("write encryption key: %w", err)
}
return nil
}