forked from godarch/darch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
children.go
58 lines (47 loc) · 1019 Bytes
/
children.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
package recipes
import (
"fmt"
"log"
"sort"
"github.com/godarch/darch/pkg/recipes"
"github.com/urfave/cli"
)
var childrenCommand = cli.Command{
Name: "children",
Usage: "list all the children for a recipe",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "reverse",
},
},
Action: func(clicontext *cli.Context) error {
var (
recipeName = clicontext.Args().First()
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)
for _, r := range rs {
if r.Inherits == current.Name {
results = append(results, r.Name)
}
}
if reverse {
sort.Sort(sort.Reverse(sort.StringSlice(results)))
}
for _, result := range results {
log.Println(result)
}
return nil
},
}