1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-12-22 15:25:48 +01:00

Factor out setUsage.

This commit is contained in:
Juliusz Chroboczek 2024-10-23 18:27:18 +02:00
parent ece4929111
commit e33029072b

View file

@ -119,6 +119,13 @@ func makePassword(pw string, algorithm string, iterations, length, saltlen, cost
}
}
func setUsage(cmd *flag.FlagSet, cmdname string, format string, args ...any) {
cmd.Usage = func() {
fmt.Fprintf(cmd.Output(), format, args...)
cmd.PrintDefaults()
}
}
func hashPasswordCmd(cmdname string, args []string) {
var algorithm string
var iterations int
@ -127,13 +134,10 @@ func hashPasswordCmd(cmdname string, args []string) {
var saltlen int
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
cmd.Usage = func() {
fmt.Fprintf(cmd.Output(),
"%v [option...] %v password [option...] password...\n",
os.Args[0], cmdname,
)
cmd.PrintDefaults()
}
setUsage(cmd, cmdname,
"%v [option...] %v [option...] password...\n",
os.Args[0], cmdname,
)
cmd.StringVar(&algorithm, "hash", "pbkdf2",
"hashing `algorithm`")
cmd.IntVar(&iterations, "iterations", 4096,