/
find.go
37 lines (29 loc) · 984 Bytes
/
find.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package commands
import (
"code.cloudfoundry.org/credhub-cli/errors"
)
type FindCommand struct {
PartialCredentialIdentifier string `short:"n" long:"name-like" description:"Find credentials whose name contains the query string"`
PathIdentifier string `short:"p" long:"path" description:"Find credentials that exist under the provided path"`
OutputJSON bool `short:"j" long:"output-json" description:"Return response in JSON format"`
ClientCommand
}
func (c *FindCommand) Execute([]string) error {
if c.PartialCredentialIdentifier != "" {
results, err := c.client.FindByPartialName(c.PartialCredentialIdentifier)
if err != nil {
return err
}
if len(results.Credentials) == 0 {
return errors.NewNoMatchingCredentialsFoundError()
}
formatOutput(c.OutputJSON, results)
} else {
output, err := c.client.FindByPath(c.PathIdentifier)
if err != nil {
return err
}
formatOutput(c.OutputJSON, output)
}
return nil
}