FinnTew commented on code in PR #895:
URL:
https://github.com/apache/incubator-seata-go/pull/895#discussion_r2375676611
##########
cmd/start.go:
##########
@@ -17,6 +17,45 @@
package main
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
+var (
Review Comment:
Maybe you can improve it as follow:
```go
var (
// Version information set by build flags
Version string
Branch string
Revision string
showVersion bool
showHelp bool
)
func init() {
flag.BoolVar(&showVersion, "version", false, "show version information")
flag.BoolVar(&showVersion, "v", false, "show version information")
flag.BoolVar(&showHelp, "help", false, "show help information")
flag.BoolVar(&showHelp, "h", false, "show help information")
}
```
##########
cmd/start.go:
##########
@@ -17,6 +17,45 @@
package main
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
+var (
+ // Version information set by build flags
+ Version string
+ Branch string
+ Revision string
+ showVersion = flag.Bool("version", false, "show version
information")
+ showVersionShort = flag.Bool("v", false, "show version information")
+)
+
func main() {
+
+ flag.Usage = func() {
Review Comment:
Remove this `Usage` block.
##########
cmd/start.go:
##########
@@ -17,6 +17,45 @@
package main
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
+var (
+ // Version information set by build flags
+ Version string
+ Branch string
+ Revision string
+ showVersion = flag.Bool("version", false, "show version
information")
+ showVersionShort = flag.Bool("v", false, "show version information")
+)
+
func main() {
+
+ flag.Usage = func() {
+ fmt.Fprintf(os.Stderr, "Usage: %s [options]\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, "\nOptions:\n")
+ flag.PrintDefaults()
+ }
+
+ flag.Parse()
+
Review Comment:
Add some check for `-h` or `-help` arg, as follow:
```go
if showHelp {
flag.Usage()
}
```
##########
cmd/start.go:
##########
@@ -17,6 +17,45 @@
package main
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
+var (
+ // Version information set by build flags
+ Version string
+ Branch string
+ Revision string
+ showVersion = flag.Bool("version", false, "show version
information")
+ showVersionShort = flag.Bool("v", false, "show version information")
+)
+
func main() {
+
+ flag.Usage = func() {
+ fmt.Fprintf(os.Stderr, "Usage: %s [options]\n", os.Args[0])
+ fmt.Fprintf(os.Stderr, "\nOptions:\n")
+ flag.PrintDefaults()
+ }
+
+ flag.Parse()
+
+ if *showVersion || *showVersionShort {
Review Comment:
Remove `showVersionShort` check.
##########
cmd/start.go:
##########
@@ -17,6 +17,45 @@
package main
+import (
+ "flag"
+ "fmt"
+ "os"
+)
+
+var (
+ // Version information set by build flags
+ Version string
+ Branch string
+ Revision string
+ showVersion = flag.Bool("version", false, "show version
information")
+ showVersionShort = flag.Bool("v", false, "show version information")
+)
+
func main() {
+
Review Comment:
Add some check conditions for `args` to ensure `-v` and `-version` appears
once and only once.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]