Skip to content

Commit

Permalink
feat: show version in command description
Browse files Browse the repository at this point in the history
  • Loading branch information
zhsj committed Jul 27, 2022
1 parent d904433 commit 2845c12
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
11 changes: 2 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bufio"
"context"
_ "embed"
"errors"
Expand All @@ -28,14 +27,8 @@ var (

func main() {
parser := flags.NewParser(&opts, flags.Default)
parser.Usage = `[OPTIONS]
Description:`
scanner := bufio.NewScanner(strings.NewReader(strings.TrimPrefix(readme, "# wghttp\n")))
for scanner.Scan() {
parser.Usage += " " + scanner.Text() + "\n"
}
parser.Usage = strings.TrimSuffix(parser.Usage, "\n")
parser.LongDescription = fmt.Sprintf("wghttp %s\n\n", version())
parser.LongDescription += strings.Trim(strings.TrimPrefix(readme, "# wghttp"), "\n")
if _, err := parser.Parse(); err != nil {
code := 1
fe := &flags.Error{}
Expand Down
14 changes: 9 additions & 5 deletions stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ func stats(dev *device.Device) func() (any, error) {
Version string
}{
NumGoroutine: runtime.NumGoroutine(),
}

info, ok := debug.ReadBuildInfo()
if ok {
stats.Version = info.Main.Version
Version: version(),
}

scanner := bufio.NewScanner(&buf)
Expand All @@ -55,3 +51,11 @@ func stats(dev *device.Device) func() (any, error) {
return stats, nil
}
}

func version() string {
info, ok := debug.ReadBuildInfo()
if ok {
return info.Main.Version
}
return "(devel)"
}

0 comments on commit 2845c12

Please sign in to comment.