diff --git a/config.go b/config.go index 04ef4aa..ea575c0 100644 --- a/config.go +++ b/config.go @@ -7,16 +7,32 @@ import ( // Parse the CLI flags func parseFlags() Config { - var config Config + var switchConf Config + defaultSwitches := Config{ + useLowerCase: true, + useUpperCase: true, + useNumber: true, + useSpecial: false, + useComplex: false, + humanReadable: false, + } + config := Config{ + useLowerCase: defaultSwitches.useLowerCase, + useUpperCase: defaultSwitches.useUpperCase, + useNumber: defaultSwitches.useNumber, + useSpecial: defaultSwitches.useSpecial, + useComplex: defaultSwitches.useComplex, + humanReadable: defaultSwitches.humanReadable, + } // Read and set all flags - flag.BoolVar(&config.useLowerCase, "L", true, "Use lower case characters in passwords") - flag.BoolVar(&config.useUpperCase, "U", true, "Use upper case characters in passwords") - flag.BoolVar(&config.useNumber, "N", true, "Use numbers in passwords") - flag.BoolVar(&config.useSpecial, "S", false, "Use special characters in passwords") - flag.BoolVar(&config.useComplex, "C", false, "Generate complex passwords (implies -L -U -N -S, disables -H)") + flag.BoolVar(&switchConf.useLowerCase, "L", false, "Use lower case characters in passwords") + flag.BoolVar(&switchConf.useUpperCase, "U", false, "Use upper case characters in passwords") + flag.BoolVar(&switchConf.useNumber, "N", false, "Use numerich characters in passwords") + flag.BoolVar(&switchConf.useSpecial, "S", false, "Use special characters in passwords") + flag.BoolVar(&switchConf.useComplex, "C", false, "Generate complex passwords (implies -L -U -N -S, disables -H)") + flag.BoolVar(&switchConf.humanReadable, "H", false, "Generate human-readable passwords") flag.BoolVar(&config.spellPassword, "l", false, "Spell generated password") - flag.BoolVar(&config.humanReadable, "H", false, "Generate human-readable passwords") flag.BoolVar(&config.showVersion, "v", false, "Show version") flag.IntVar(&config.minPassLen, "m", DefaultMinLenght, "Minimum password length") flag.IntVar(&config.maxPassLen, "x", DefaultMaxLenght, "Maxiumum password length") @@ -26,7 +42,27 @@ func parseFlags() Config { "New style password parameters (higher priority than single parameters)") flag.Parse() - // Parse additional parameters + // Invert-switch the defaults + if switchConf.useLowerCase { + config.useLowerCase = !defaultSwitches.useLowerCase + } + if switchConf.useUpperCase { + config.useUpperCase = !defaultSwitches.useUpperCase + } + if switchConf.useNumber { + config.useNumber = !defaultSwitches.useNumber + } + if switchConf.useSpecial { + config.useSpecial = !defaultSwitches.useSpecial + } + if switchConf.useComplex { + config.useComplex = !defaultSwitches.useComplex + } + if switchConf.humanReadable { + config.humanReadable = !defaultSwitches.humanReadable + } + + // Parse additional parameters and new-style switches parseParams(&config) return config