Check arguments before looking for the mnemonic (closes #79)
check / check (push) Waiting to run
check / check (push) Waiting to run
The key index, --words, the --to recipients and the input file of age encrypt and age decrypt were checked only after the mnemonic had been obtained, so a run that could not succeed still prompted for it or ran the mnemonic command. options.Index now refuses an index above derive.MaxIndex, which covers every command group; the mnemonic command calls the new childmnemonic.CheckWords first; age encrypt reads its recipients with the new agekey.Recipients, and both age commands open their input, before the key is derived. The README says which checks come first. Judgement call: the -o path is still looked at after the mnemonic. Model: opus-5-5
This commit was merged in pull request #84.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sneak.berlin/go/keyfunc/internal/derive"
|
||||
"sneak.berlin/go/keyfunc/internal/mnemonic"
|
||||
)
|
||||
|
||||
@@ -23,13 +24,20 @@ func Add(cmd *cobra.Command) {
|
||||
)
|
||||
}
|
||||
|
||||
// Index returns the key index the user asked for.
|
||||
// Index returns the key index the user asked for, and refuses one above
|
||||
// derive.MaxIndex. Every command calls it before it looks for the
|
||||
// mnemonic.
|
||||
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)
|
||||
}
|
||||
|
||||
err = derive.CheckIndex(index)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return index, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user