args... still needs charset minimums (how?)

This commit is contained in:
2022-03-03 04:26:44 -05:00
parent 1cb6879786
commit 480dcd7e24
11 changed files with 254 additions and 2 deletions

17
cmd/pwgen/args.go Normal file
View File

@@ -0,0 +1,17 @@
package main
// Arguments contains the invocation arguments.
type Arguments struct {
NoAlpha bool `short:"a" long:"disable-alpha" description:"If specified, do NOT include the Alphabetical (letter) charset."`
NoNum bool `short:"n" long:"disable-num" description:"If specified, do NOT include the Numerical (number) charset."`
NoSymbols bool `short:"s" long:"disable-symbols" description:"If specified, do NOT include the Simple Symbols charset."`
ExtendSymbols bool `short:"S" long:"enable-extended-symbols" description:"If specified, include the Extended Symbols charset (these characters may cause issues in some applications)."`
NumUpper uint `short:"u" long:"count-upper" description:"The number of minimum uppercase characters. If not specified, this is random (if in the charset)."`
NumLower uint `short:"U" long:"count-lower" description:"The number of minimum lowercase characters. If not specified, this is random (if in the charset)."`
NumSymbols uint `short:"y" long:"count-symbols" description:"The number of minimum simple symbol characters. If not specified, this is random (if in the charset)."`
NumExtended uint `short:"Y" long:"count-extended" description:"The number of minimum extended symbol characters. If not specified, this is random (if in the charset)."`
DisableChars uint `short:"d" long:"disable-chars" description:"If specified, this string of chars should be explicitly excluded from the charset(s)."`
MinLen uint `short:"l" long:"min-length" default:"16" description:"The minimum length for passwords; use 0 for no minimum limit. Set this to the same as -L/--max-length to use a fixed length."`
MaxLen uint `short:"L" long:"max-length" default:"64" description:"The maximum length for passwords; use 0 for no maximum limit (this is hard-capped to 256 for performance reasons). Set this to the same as -l/--min-length for a fixed length. Must be >= -l/--min-length."`
Count uint `short:"c" long:"count" default:"1" description:"The number of passwords to generate."`
}

49
cmd/pwgen/main.go Normal file
View File

@@ -0,0 +1,49 @@
package main
import (
"fmt"
"log"
"os"
"github.com/jessevdk/go-flags"
"r00t2.io/pwgen/pwgenerator"
)
var a Arguments
func main() {
var err error
var genOpts *pwgenerator.GenOpts
if _, err = flags.Parse(&a); err != nil {
switch flagsErr := err.(type) {
case *flags.Error:
if flagsErr.Type == flags.ErrHelp {
os.Exit(0)
}
log.Panicln(err)
default:
log.Panicln(err)
}
}
genOpts = &pwgenerator.GenOpts{
Alpha: !a.NoAlpha,
Numeric: !a.NoNum,
Symbols: !a.NoSymbols,
ExtendedSymbols: a.ExtendSymbols,
CountUpper: a.NumUpper,
CountLower: a.NumLower,
CountSymbols: a.NumSymbols,
CountExtended: a.NumExtended,
DisabledChars: nil,
LengthMin: a.MinLen,
LengthMax: a.MaxLen,
Count: a.Count,
}
fmt.Printf("%#v\n", a)
fmt.Printf("%#v\n", genOpts)
}