MCPcopy Create free account
hub / github.com/cloudwan/gohan / getGetCommand

Method getGetCommand

cli/client/commands.go:84–124  ·  view source on GitHub ↗
(s *schema.Schema)

Source from the content-addressed store, hash-verified

82}
83
84func (gohanClientCLI *GohanClientCLI) getGetCommand(s *schema.Schema) gohanCommand {
85 return gohanCommand{
86 Name: fmt.Sprintf("%s show", s.ID),
87 Schema: s,
88 Action: func(args []string) (string, error) {
89 if len(args) < 1 {
90 return "", fmt.Errorf("Wrong number of arguments")
91 }
92 _, err := gohanClientCLI.handleArguments(args[:len(args)-1], s)
93 if err != nil {
94 return "", err
95 }
96 id, err := gohanClientCLI.getResourceID(s, args[len(args)-1])
97 if err != nil {
98 return "", err
99 }
100 url := fmt.Sprintf("%s%s/%s%s", gohanClientCLI.opts.gohanEndpointURL, s.URL, id, gohanClientCLI.getFieldsParam(true))
101 result, err := gohanClientCLI.request("GET", url, nil)
102 if err != nil {
103 return "", err
104 }
105 buffer := bytes.NewBufferString("")
106 buffer.WriteString(gohanClientCLI.formatOutput(s, result))
107 for _, childSchema := range gohanClientCLI.schemas {
108 if s.ID == childSchema.Parent {
109 buffer.WriteString("\n")
110 buffer.WriteString(childSchema.Title)
111 buffer.WriteString("\n")
112 parentSchemaPropertyID := childSchema.ParentSchemaPropertyID()
113 url := fmt.Sprintf("%s%s?%s=%s%s", gohanClientCLI.opts.gohanEndpointURL, childSchema.URL, parentSchemaPropertyID, id, gohanClientCLI.getFieldsParam(false))
114 result, err := gohanClientCLI.request("GET", url, nil)
115 if err != nil {
116 return "", err
117 }
118 buffer.WriteString(gohanClientCLI.formatOutput(childSchema, result))
119 }
120 }
121 return buffer.String(), nil
122 },
123 }
124}
125
126func (gohanClientCLI *GohanClientCLI) getPostCommand(s *schema.Schema) gohanCommand {
127 return gohanCommand{

Callers 2

getCommandsMethod · 0.95
client_test.goFile · 0.80

Calls 8

handleArgumentsMethod · 0.95
getResourceIDMethod · 0.95
getFieldsParamMethod · 0.95
requestMethod · 0.95
formatOutputMethod · 0.95
ErrorfMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected