-
Notifications
You must be signed in to change notification settings - Fork 6
/
find.go
53 lines (44 loc) · 960 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
Copyright 2021 Adevinta
*/
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/adevinta/vulcan-api/cmd/vulcan-cli/cli"
)
var FindTeam = &cobra.Command{
Use: `find <teams_dir> <asset1> [asset2 ...]`,
Short: `Find the teams an asset pertains to in the local teams directory`,
Args: cobra.MinimumNArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return runFindTeam(args)
},
}
func init() {
rootCmd.AddCommand(FindTeam)
}
func runFindTeam(args []string) error {
path := args[0]
assets := args[1:]
teams, err := cli.ReadLocalTeams(path)
if err != nil {
return err
}
for _, a := range assets {
found := false
for _, t := range teams {
_, ok := t.Assets.FindByTarget(a)
if ok {
found = true
fmt.Fprintf(os.Stderr, "[*] Found %s: '%s'\n", a, t.Name)
fmt.Printf("%s;%s\n", a, t.Name)
}
}
if !found {
fmt.Fprintf(os.Stderr, "[*] NOT Found '%s'\n", a)
}
}
return nil
}