1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-13 20:25: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) { func hashPasswordCmd(cmdname string, args []string) {
var algorithm string var algorithm string
var iterations int var iterations int
@ -127,13 +134,10 @@ func hashPasswordCmd(cmdname string, args []string) {
var saltlen int var saltlen int
cmd := flag.NewFlagSet(cmdname, flag.ExitOnError) cmd := flag.NewFlagSet(cmdname, flag.ExitOnError)
cmd.Usage = func() { setUsage(cmd, cmdname,
fmt.Fprintf(cmd.Output(), "%v [option...] %v [option...] password...\n",
"%v [option...] %v password [option...] password...\n", os.Args[0], cmdname,
os.Args[0], cmdname, )
)
cmd.PrintDefaults()
}
cmd.StringVar(&algorithm, "hash", "pbkdf2", cmd.StringVar(&algorithm, "hash", "pbkdf2",
"hashing `algorithm`") "hashing `algorithm`")
cmd.IntVar(&iterations, "iterations", 4096, cmd.IntVar(&iterations, "iterations", 4096,