Files
keyfunc/internal/cli/mnemonic/mnemonic.go
T
sneak 72dd386bbf
check / check (push) Successful in 54s
Move the Go module to sneak.berlin/go/keyfunc (closes #15)
REPO_POLICIES.md sets the Go module root to sneak.berlin/go/<name>.
go.mod, every import of the old path and the -X path in the Makefile
LDFLAGS now use sneak.berlin/go/keyfunc; make fmt moved those imports
to their new place in the sort order. The old path keeps no alias. The
README gives the go install line next to the build from a clone and
drops this issue from its TODO list.

Model: opus-5-5
2026-10-03 12:10:07 +00:00

66 lines
1.4 KiB
Go

// Package mnemonic is the command that prints a child mnemonic.
package mnemonic
import (
"fmt"
"github.com/spf13/cobra"
"sneak.berlin/go/keyfunc/internal/childmnemonic"
"sneak.berlin/go/keyfunc/internal/cli/options"
"sneak.berlin/go/keyfunc/internal/derive"
)
// Command returns the mnemonic command.
func Command() *cobra.Command {
cmd := &cobra.Command{
Use: "mnemonic",
Short: "print a child mnemonic derived from the main one",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
child, err := derived(cmd)
if err != nil {
return err
}
_, err = fmt.Fprintln(cmd.OutOrStdout(), child)
if err != nil {
return fmt.Errorf("writing the mnemonic: %w", err)
}
return nil
},
}
cmd.Flags().Uint32(
"words", childmnemonic.DefaultWords,
"how long the child mnemonic is: 12, 18 or 24 words",
)
return cmd
}
// derived returns the child mnemonic this run asks for.
func derived(cmd *cobra.Command) (string, error) {
index, err := options.Index(cmd)
if err != nil {
return "", err
}
words, err := cmd.Flags().GetUint32("words")
if err != nil {
return "", fmt.Errorf("reading the word count: %w", err)
}
parent, err := options.Mnemonic(cmd)
if err != nil {
return "", err
}
master, err := derive.Master(parent)
if err != nil {
return "", err
}
return childmnemonic.Derive(master, words, index)
}