1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 08:35:57 +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",
setUsage(cmd, cmdname,
"%v [option...] %v [option...] password...\n",
os.Args[0], cmdname,
)
cmd.PrintDefaults()
}
cmd.StringVar(&algorithm, "hash", "pbkdf2",
"hashing `algorithm`")
cmd.IntVar(&iterations, "iterations", 4096,