v0.2.9: Replaced standard go-help with custom usage text

This commit is contained in:
Winni Neessen 2021-03-28 11:51:26 +02:00
parent d3648d18a9
commit 0c371569c0
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 49 additions and 2 deletions

View file

@ -70,7 +70,27 @@
<recent name="C:\Users\Winni Neessen\go\src\apg.go\test" />
</key>
</component>
<component name="RunManager" selected="Go Test.Benchmark Application">
<component name="RunManager" selected="Go Build.Run Application (show help text)">
<configuration name="Run Application (show help text)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="-h" />
<kind value="PACKAGE" />
<filePath value="$PROJECT_DIR$" />
<package value="github.com/wneessen/apg.go" />
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="Run Application (show version string)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="-v" />
<kind value="PACKAGE" />
<filePath value="$PROJECT_DIR$" />
<package value="github.com/wneessen/apg.go" />
<directory value="$PROJECT_DIR$" />
<method v="2" />
</configuration>
<configuration name="Run Application (with excludes)" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="apg.go" />
<working_directory value="$PROJECT_DIR$" />
@ -157,6 +177,8 @@
<item itemvalue="Go Build.Run Application (with newstyle params)" />
<item itemvalue="Go Build.Run Application (with newstyle params and spelling)" />
<item itemvalue="Go Build.Run Application (with newstyle params and spelling and multiple pws)" />
<item itemvalue="Go Build.Run Application (show help text)" />
<item itemvalue="Go Build.Run Application (show version string)" />
<item itemvalue="Go Test.Test Application" />
<item itemvalue="Go Test.Benchmark Application" />
</list>
@ -206,7 +228,9 @@
<MESSAGE value="Updated .gitignore" />
<MESSAGE value="Removed .idea from .gitignore" />
<MESSAGE value="Let's have centralized IDE config" />
<option name="LAST_COMMIT_MESSAGE" value="Let's have centralized IDE config" />
<MESSAGE value="New DEV branch" />
<MESSAGE value="v0.2.9: Replaced standard go-help with custom usage text" />
<option name="LAST_COMMIT_MESSAGE" value="v0.2.9: Replaced standard go-help with custom usage text" />
</component>
<component name="VgoProject">
<integration-enabled>true</integration-enabled>

23
apg.go
View file

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"log"
"os"
@ -28,12 +29,34 @@ type Config struct {
outputMode int
}
// Help text
const usage = `Usage:
apg [-m <length>] [-x <length>] -L -U -N -S -H
apg [-m <length>] [-x <length>] -M LUNsh -E <list of chars>
Options:
-m LENGTH Minimum length of the password to be generated (Default: 20)
-x LENGTH Maximum length of the password to be generated (Default: 20)
-n NUMBER Amount of password to be generated (Default: 1)
-E CHARS List of characters to be excluded in the generated password
-M [LUNSHClunshc] New style password parameters (upper case: on, lower case: off)
-L Use lower case characters in passwords (Default: on)
-U Use upper case characters in passwords (Default: on)
-N Use numeric characters in passwords (Default: on)
-S Use special characters in passwords (Default: on)
-H Avoid ambiguous characters in passwords (i. e.: 1, l, I, O, 0) (Default: off)
-C Enable complex password mode (implies -L -U -N -S and disables -H) (Default: off)
-l Spell generated passwords in phonetic alphabet (Default: off)
-h Show this help text
-v Show version string`
// Main function that generated the passwords and returns them
func main() {
// Log config
log.SetFlags(log.Ltime | log.Ldate | log.Lshortfile)
// Read and parse flags
flag.Usage = func() { _, _ = fmt.Fprintf(os.Stderr, "%s\n", usage) }
var config = parseFlags()
// Show version and exit