| OLD | NEW |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "fmt" | 8 "fmt" |
| 9 "os" | 9 "os" |
| 10 "strings" | 10 "strings" |
| 11 | 11 |
| 12 "github.com/maruel/subcommands" | 12 "github.com/maruel/subcommands" |
| 13 "golang.org/x/net/context" | 13 "golang.org/x/net/context" |
| 14 "google.golang.org/genproto/protobuf" |
| 14 | 15 |
| 15 "github.com/luci/luci-go/common/cli" | 16 "github.com/luci/luci-go/common/cli" |
| 16 » "github.com/luci/luci-go/common/proto/google/descriptor" | 17 » "github.com/luci/luci-go/common/proto/google/descutil" |
| 17 "github.com/luci/luci-go/grpc/prpc" | 18 "github.com/luci/luci-go/grpc/prpc" |
| 18 ) | 19 ) |
| 19 | 20 |
| 20 var cmdShow = &subcommands.Command{ | 21 var cmdShow = &subcommands.Command{ |
| 21 UsageLine: `show [flags] <server> [name] | 22 UsageLine: `show [flags] <server> [name] |
| 22 | 23 |
| 23 server: host ("example.com") or port for localhost (":8080"). | 24 server: host ("example.com") or port for localhost (":8080"). |
| 24 name: a full name of service, method or type. If not specified prints names | 25 name: a full name of service, method or type. If not specified prints names |
| 25 of all available services.`, | 26 of all available services.`, |
| 26 ShortDesc: "lists services and prints a definition of a referenced objec
t.", | 27 ShortDesc: "lists services and prints a definition of a referenced objec
t.", |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 return fmt.Errorf("could not load server description: %s", err) | 69 return fmt.Errorf("could not load server description: %s", err) |
| 69 } | 70 } |
| 70 | 71 |
| 71 if name == "" { | 72 if name == "" { |
| 72 for _, s := range desc.Services { | 73 for _, s := range desc.Services { |
| 73 fmt.Println(s) | 74 fmt.Println(s) |
| 74 } | 75 } |
| 75 return nil | 76 return nil |
| 76 } | 77 } |
| 77 | 78 |
| 78 » file, obj, path := desc.Description.Resolve(name) | 79 » file, obj, path := descutil.Resolve(desc.Description, name) |
| 79 if obj == nil { | 80 if obj == nil { |
| 80 return fmt.Errorf("name %q could not resolved", name) | 81 return fmt.Errorf("name %q could not resolved", name) |
| 81 } | 82 } |
| 82 | 83 |
| 83 print := newPrinter(os.Stdout) | 84 print := newPrinter(os.Stdout) |
| 84 print.File = file | 85 print.File = file |
| 85 | 86 |
| 86 switch obj := obj.(type) { | 87 switch obj := obj.(type) { |
| 87 | 88 |
| 88 case *descriptor.ServiceDescriptorProto: | 89 case *descriptor.ServiceDescriptorProto: |
| 89 print.Service(obj, path[1], -1) | 90 print.Service(obj, path[1], -1) |
| 90 | 91 |
| 91 case *descriptor.MethodDescriptorProto: | 92 case *descriptor.MethodDescriptorProto: |
| 92 serviceIndex, methodIndex := path[1], path[3] | 93 serviceIndex, methodIndex := path[1], path[3] |
| 93 print.Service(file.Service[serviceIndex], serviceIndex, methodIn
dex) | 94 print.Service(file.Service[serviceIndex], serviceIndex, methodIn
dex) |
| 94 | 95 |
| 95 printMsg := func(name string) { | 96 printMsg := func(name string) { |
| 96 name = strings.TrimPrefix(name, ".") | 97 name = strings.TrimPrefix(name, ".") |
| 97 » » » file, msg, path := desc.Description.Resolve(name) | 98 » » » file, msg, path := descutil.Resolve(desc.Description, na
me) |
| 98 if msg == nil { | 99 if msg == nil { |
| 99 print.Printf("// Message %q is not found\n", nam
e) | 100 print.Printf("// Message %q is not found\n", nam
e) |
| 100 return | 101 return |
| 101 } | 102 } |
| 102 print.File = file | 103 print.File = file |
| 103 print.Message(msg.(*descriptor.DescriptorProto), path) | 104 print.Message(msg.(*descriptor.DescriptorProto), path) |
| 104 } | 105 } |
| 105 | 106 |
| 106 print.Printf("\n") | 107 print.Printf("\n") |
| 107 printMsg(obj.GetInputType()) | 108 printMsg(obj.GetInputType()) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 119 | 120 |
| 120 case *descriptor.EnumValueDescriptorProto: | 121 case *descriptor.EnumValueDescriptorProto: |
| 121 print.EnumValue(obj, path) | 122 print.EnumValue(obj, path) |
| 122 | 123 |
| 123 default: | 124 default: |
| 124 return fmt.Errorf("object of type %T is not supported", obj) | 125 return fmt.Errorf("object of type %T is not supported", obj) |
| 125 } | 126 } |
| 126 | 127 |
| 127 return print.Err | 128 return print.Err |
| 128 } | 129 } |
| OLD | NEW |