Files
keyfunc/internal/cli/options/options.go
sneak 90a7c96cd1
All checks were successful
check / check (push) Successful in 34s
Skeleton, mnemonic input, derivation, and the ssh commands (closes #1)
The tool derives ed25519 SSH keys from a BIP-39 mnemonic and prints
them, either as an authorized_keys line or as an unencrypted OpenSSH
private key. Both README test vectors are asserted in the tests.

The mnemonic is looked for in the order the README gives, and refused
when it fails its checksum or when there is nowhere left to look.

The repository standards come with it: the vendored linter
configuration and policies, the script/ entrypoints with a thin
Makefile, and a Gitea workflow. Linting happens only inside the image
built from Dockerfile.lint, which pins the linter by hash, so the root
Dockerfile runs the formatting check, the tests and the build, and
script/cibuild runs the linter before it.

Model: opus-5
2026-09-07 14:44:45 +00:00

44 lines
1.1 KiB
Go

// Package options holds the flags that every command has and reads
// them back.
package options
import (
"fmt"
"git.eeqj.de/sneak/keyfunc/internal/mnemonic"
"github.com/spf13/cobra"
)
// Add gives a command the flags that every command has. They are
// persistent, so every command below it has them too.
func Add(cmd *cobra.Command) {
cmd.PersistentFlags().String(
"mnemonic-command", "",
"shell command whose output is the mnemonic",
)
cmd.PersistentFlags().Uint32P(
"index", "n", 0,
"which key to derive",
)
}
// Index returns the key index the user asked for.
func Index(cmd *cobra.Command) (uint32, error) {
index, err := cmd.Flags().GetUint32("index")
if err != nil {
return 0, fmt.Errorf("reading the index: %w", err)
}
return index, nil
}
// Mnemonic returns the mnemonic, from the first source that has one.
func Mnemonic(cmd *cobra.Command) (string, error) {
command, err := cmd.Flags().GetString("mnemonic-command")
if err != nil {
return "", fmt.Errorf("reading the mnemonic command: %w", err)
}
return mnemonic.Read(cmd.Context(), command)
}