Files
keyfunc/internal/cli/options/options.go
T
clawbot 8d1c873bb7
check / check (push) Successful in 1m33s
Move the Go module to sneak.berlin/go/keyfunc (closes #15)
The module path becomes sneak.berlin/go/keyfunc, as the repo policy sets for Go modules: go.mod, every import and the -X path in the Makefile. The old path gets no alias. The README gives a go install line for the new path, which resolves with @latest only once main carries the move, and its TODO list now names the open 1.0 issues.

Model: opus-5-5
2026-10-04 01:42:43 +02:00

44 lines
1.1 KiB
Go

// Package options holds the flags that every command has and reads
// them back.
package options
import (
"fmt"
"github.com/spf13/cobra"
"sneak.berlin/go/keyfunc/internal/mnemonic"
)
// 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)
}