Print size of the message in very verbose mode (#181)

Adds -vv flag for "very verbose".
Includes estimated message size when enabled. The size is an estimate because it is the canonical size for the proto message, but not necessarily its actual on-the-wire size.
This commit is contained in:
Sergei Vorobev
2020-08-14 08:02:42 -07:00
committed by GitHub
parent 41a6ac0479
commit e544b9e66f
4 changed files with 70 additions and 29 deletions

View File

@@ -135,6 +135,8 @@ var (
When describing messages, show a template of input data.`))
verbose = flags.Bool("v", false, prettify(`
Enable verbose output.`))
veryVerbose = flags.Bool("vv", false, prettify(`
Enable very verbose output.`))
serverName = flags.String("servername", "", prettify(`
Override server name when validating TLS certificate. This flag is
ignored if -plaintext or -insecure is used.
@@ -316,6 +318,14 @@ func main() {
invoke = true
}
verbosityLevel := 0
if *verbose {
verbosityLevel = 1
}
if *veryVerbose {
verbosityLevel = 2
}
var symbol string
if invoke {
if len(args) == 0 {
@@ -651,7 +661,7 @@ func main() {
// if not verbose output, then also include record delimiters
// between each message, so output could potentially be piped
// to another grpcurl process
includeSeparators := !*verbose
includeSeparators := verbosityLevel == 0
options := grpcurl.FormatOptions{
EmitJSONDefaultFields: *emitDefaults,
IncludeTextSeparator: includeSeparators,
@@ -661,7 +671,11 @@ func main() {
if err != nil {
fail(err, "Failed to construct request parser and formatter for %q", *format)
}
h := grpcurl.NewDefaultEventHandler(os.Stdout, descSource, formatter, *verbose)
h := &grpcurl.DefaultEventHandler{
Out: os.Stdout,
Formatter: formatter,
VerbosityLevel: verbosityLevel,
}
err = grpcurl.InvokeRPC(ctx, descSource, cc, symbol, append(addlHeaders, rpcHeaders...), h, rf.Next)
if err != nil {
@@ -676,7 +690,7 @@ func main() {
if h.NumResponses != 1 {
respSuffix = "s"
}
if *verbose {
if verbosityLevel > 0 {
fmt.Printf("Sent %d request%s and received %d response%s\n", reqCount, reqSuffix, h.NumResponses, respSuffix)
}
if h.Status.Code() != codes.OK {