@@ -59,13 +59,14 @@ var (
59
59
rpcHeaders multiString
60
60
reflHeaders multiString
61
61
expandHeaders = flags .Bool ("expand-headers" , false , prettify (`
62
- If set, headers may use '${NAME}' syntax to reference environment variables.
63
- These will be expanded to the actual environment variable value before
64
- sending to the server. For example, if there is an environment variable
65
- defined like FOO=bar, then a header of 'key: ${FOO}' would expand to 'key: bar'.
66
- This applies to -H, -rpc-header, and -reflect-header options. No other
67
- expansion/escaping is performed. This can be used to supply
68
- credentials/secrets without having to put them in command-line arguments.` ))
62
+ If set, headers may use '${NAME}' syntax to reference environment
63
+ variables. These will be expanded to the actual environment variable
64
+ value before sending to the server. For example, if there is an
65
+ environment variable defined like FOO=bar, then a header of
66
+ 'key: ${FOO}' would expand to 'key: bar'. This applies to -H,
67
+ -rpc-header, and -reflect-header options. No other expansion/escaping is
68
+ performed. This can be used to supply credentials/secrets without having
69
+ to put them in command-line arguments.` ))
69
70
authority = flags .String ("authority" , "" , prettify (`
70
71
Value of :authority pseudo-header to be use with underlying HTTP/2
71
72
requests. It defaults to the given address.` ))
@@ -101,6 +102,13 @@ var (
101
102
will accept. If not specified, defaults to 4,194,304 (4 megabytes).` ))
102
103
emitDefaults = flags .Bool ("emit-defaults" , false , prettify (`
103
104
Emit default values for JSON-encoded responses.` ))
105
+ protosetOut = flags .String ("protoset-out" , "" , prettify (`
106
+ The name of a file to be written that will contain a FileDescriptorSet
107
+ proto. With the list and describe verbs, the listed or described
108
+ elements and their transitive dependencies will be written to the named
109
+ file if this option is given. When invoking an RPC and this option is
110
+ given, the method being invoked and its transitive dependencies will be
111
+ included in the output file.` ))
104
112
msgTemplate = flags .Bool ("msg-template" , false , prettify (`
105
113
When describing messages, show a template of input data.` ))
106
114
verbose = flags .Bool ("v" , false , prettify (`
@@ -391,6 +399,9 @@ func main() {
391
399
fmt .Printf ("%s\n " , svc )
392
400
}
393
401
}
402
+ if err := writeProtoset (descSource , svcs ... ); err != nil {
403
+ fail (err , "Failed to write protoset to %s" , * protosetOut )
404
+ }
394
405
} else {
395
406
methods , err := grpcurl .ListMethods (descSource , symbol )
396
407
if err != nil {
@@ -403,6 +414,9 @@ func main() {
403
414
fmt .Printf ("%s\n " , m )
404
415
}
405
416
}
417
+ if err := writeProtoset (descSource , symbol ); err != nil {
418
+ fail (err , "Failed to write protoset to %s" , * protosetOut )
419
+ }
406
420
}
407
421
408
422
} else if describe {
@@ -503,6 +517,9 @@ func main() {
503
517
fmt .Println (str )
504
518
}
505
519
}
520
+ if err := writeProtoset (descSource , symbols ... ); err != nil {
521
+ fail (err , "Failed to write protoset to %s" , * protosetOut )
522
+ }
506
523
507
524
} else {
508
525
// Invoke an RPC
@@ -619,3 +636,15 @@ func fail(err error, msg string, args ...interface{}) {
619
636
exit (2 )
620
637
}
621
638
}
639
+
640
+ func writeProtoset (descSource grpcurl.DescriptorSource , symbols ... string ) error {
641
+ if * protosetOut == "" {
642
+ return nil
643
+ }
644
+ f , err := os .Create (* protosetOut )
645
+ if err != nil {
646
+ return err
647
+ }
648
+ defer f .Close ()
649
+ return grpcurl .WriteProtoset (f , descSource , symbols ... )
650
+ }
0 commit comments