Skip to content

Commit

Permalink
main: flag aliases
Browse files Browse the repository at this point in the history
Signed-off-by: He Xian <[email protected]>
  • Loading branch information
hexian000 committed Nov 29, 2024
1 parent 82010d6 commit b381dd1
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions v3/cmd/tlswrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,31 @@ package main

import (
"flag"
"fmt"
"os"

"github.com/hexian000/gosnippets/slog"
"github.com/hexian000/tlswrapper/v3"
)

var flagAlias = map[string]string{
"help": "h",
"config": "c",
}

func parseFlags(f *tlswrapper.AppFlags) {
flag.BoolVar(&f.Help, "h", false, "help")
flag.StringVar(&f.Config, "c", "", "config file")
flag.BoolVar(&f.Help, "help", false, "show usage and exit")
flag.StringVar(&f.Config, "config", "", "config file")
flag.BoolVar(&f.DumpConfig, "dumpconfig", false, "dump config file to stdout")
flag.StringVar(&f.ServerName, "sni", "example.com", "server name")
flag.StringVar(&f.GenCerts, "gencerts", "", "comma-separated name list, generate key pairs as <name>-cert.pem, <name>-key.pem")
flag.StringVar(&f.Sign, "sign", "", "sign the certificate with <name>-cert.pem, <name>-key.pem")
flag.StringVar(&f.KeyType, "keytype", "rsa", "one of rsa, ecdsa, ed25519")
flag.IntVar(&f.KeySize, "keysize", 0, "specifies the size of the private key, depending on the key type")
for from, to := range flagAlias {
flagSet := flag.Lookup(from)
flag.Var(flagSet.Value, to, fmt.Sprintf("alias to %q", flagSet.Name))
}
flag.Parse()
}

Expand Down

0 comments on commit b381dd1

Please sign in to comment.