fix: flag of version and help

This commit is contained in:
2024-10-12 16:24:27 +08:00
parent 747ee080c8
commit 495448254e
4 changed files with 15 additions and 9 deletions

View File

@@ -110,15 +110,17 @@ const defaultConfigFile = "./etc/capconf.yaml"
func init() { func init() {
cfile := flag.String("c", defaultConfigFile, "config file") cfile := flag.String("c", defaultConfigFile, "config file")
pv := flag.Bool("version", false, "print version") pv := flag.Bool("v", false, "print version")
ph := flag.Bool("help", false, "print help") pversion := flag.Bool("version", false, "print version")
ph := flag.Bool("h", false, "print help")
phelp := flag.Bool("help", false, "print help")
flag.Parse() flag.Parse()
if *pv { if *pv || *pversion {
fmt.Printf("OMC captrace version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer) fmt.Printf("OMC captrace version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
os.Exit(0) os.Exit(0)
} }
if *ph { if *ph || *phelp {
flag.Usage() flag.Usage()
os.Exit(0) os.Exit(0)
} }

View File

@@ -179,14 +179,16 @@ var ConfigFile *string
func init() { func init() {
ConfigFile = flag.String("c", defaultConfigFile, "config file") ConfigFile = flag.String("c", defaultConfigFile, "config file")
pv := flag.Bool("v", false, "print version") pv := flag.Bool("v", false, "print version")
pversion := flag.Bool("version", false, "print version")
ph := flag.Bool("h", false, "print help") ph := flag.Bool("h", false, "print help")
phelp := flag.Bool("help", false, "print help")
flag.Parse() flag.Parse()
if *pv { if *pv || *pversion {
fmt.Printf("OMC crontask version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer) fmt.Printf("OMC crontask version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
os.Exit(0) os.Exit(0)
} }
if *ph { if *ph || *phelp {
flag.Usage() flag.Usage()
os.Exit(0) os.Exit(0)
} }

View File

@@ -31,7 +31,7 @@ case "$1" in
;; ;;
version) version)
for procName in $ProcList;do for procName in $ProcList;do
$BinDir/$procName -v $BinDir/$procName --version
done done
;; ;;
*) *)

View File

@@ -167,14 +167,16 @@ const DefaultConfigFile = "./etc/sshsvc.yaml"
func init() { func init() {
cfile := flag.String("c", DefaultConfigFile, "config file") cfile := flag.String("c", DefaultConfigFile, "config file")
pv := flag.Bool("v", false, "print version") pv := flag.Bool("v", false, "print version")
pversion := flag.Bool("version", false, "print version")
ph := flag.Bool("h", false, "print help") ph := flag.Bool("h", false, "print help")
phelp := flag.Bool("help", false, "print help")
flag.Parse() flag.Parse()
if *pv { if *pv || *pversion {
fmt.Printf("OMC sshsvc version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer) fmt.Printf("OMC sshsvc version: %s\n%s\n%s\n\n", global.Version, global.BuildTime, global.GoVer)
os.Exit(0) os.Exit(0)
} }
if *ph { if *ph || *phelp {
flag.Usage() flag.Usage()
os.Exit(0) os.Exit(0)
} }