Skip to content

Commit

Permalink
Add version information in help
Browse files Browse the repository at this point in the history
  • Loading branch information
Bradley Kemp committed Jun 17, 2019
1 parent 7aeda45 commit d142d64
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions grpc-dump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"github.com/bradleyjkemp/grpc-tools/grpc-proxy"
"github.com/bradleyjkemp/grpc-tools/internal/proto_descriptor"
_ "github.com/bradleyjkemp/grpc-tools/internal/versionflag"
"github.com/jhump/protoreflect/desc"
"os"
"strings"
Expand Down
1 change: 1 addition & 0 deletions grpc-fixture/grpc-fixture.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"github.com/bradleyjkemp/grpc-tools/grpc-proxy"
_ "github.com/bradleyjkemp/grpc-tools/internal/versionflag"
"os"
)

Expand Down
1 change: 1 addition & 0 deletions grpc-replay/grpc-replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/bradleyjkemp/grpc-tools/internal"
"github.com/bradleyjkemp/grpc-tools/internal/codec"
"github.com/bradleyjkemp/grpc-tools/internal/marker"
_ "github.com/bradleyjkemp/grpc-tools/internal/versionflag"
"golang.org/x/net/context"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down
1 change: 1 addition & 0 deletions grpc-view/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/bradleyjkemp/grpc-tools/internal"
_ "github.com/bradleyjkemp/grpc-tools/internal/versionflag"
"github.com/rivo/tview"
"io"
"os"
Expand Down
20 changes: 20 additions & 0 deletions internal/versionflag/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package versionflag

import (
"flag"
"fmt"
"os"
"runtime/debug"
)

func init() {
version := "non-module"
if info, ok := debug.ReadBuildInfo(); ok {
version = info.Main.Version
}

flag.Usage = func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s (%s):\n", os.Args[0], version)
flag.PrintDefaults()
}
}

0 comments on commit d142d64

Please sign in to comment.