-
Notifications
You must be signed in to change notification settings - Fork 32
/
parents.go
69 lines (58 loc) · 1.29 KB
/
parents.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package recipes
import (
"fmt"
"log"
"github.com/godarch/darch/pkg/recipes"
"github.com/godarch/darch/pkg/utils"
"github.com/urfave/cli"
)
var parentsCommand = cli.Command{
Name: "parents",
Usage: "list all the parents of a recipe",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "exclude-external",
},
cli.BoolFlag{
Name: "reverse",
},
},
Action: func(clicontext *cli.Context) error {
var (
recipeName = clicontext.Args().First()
excludeExternal = clicontext.Bool("exclude-external")
reverse = clicontext.Bool("reverse")
)
if len(recipeName) == 0 {
return fmt.Errorf("You must provide a recipe name")
}
rs, err := recipes.GetAllRecipes(getRecipesDir(clicontext))
if err != nil {
return err
}
current, ok := rs[recipeName]
if !ok {
return fmt.Errorf("Recipe %s doesn't exist", recipeName)
}
results := make([]string, 0)
finished := false
for finished != true {
if current.InheritsExternal {
if !excludeExternal {
results = append(results, current.Inherits)
}
finished = true
} else {
current = rs[current.Inherits]
results = append(results, current.Name)
}
}
if reverse {
results = utils.Reverse(results)
}
for _, result := range results {
log.Println(result)
}
return nil
},
}