@@ -23,6 +23,7 @@ package features
2323import (
2424 "fmt"
2525 "os"
26+ "strings"
2627 "sync"
2728
2829 "github.com/spf13/cobra"
@@ -34,23 +35,21 @@ import (
3435
3536const prefixArg = "deployment.feature"
3637
37- var features = map [ string ] Feature {}
38+ var features Features
3839var featuresLock sync.Mutex
3940var enableAll = false
4041
4142func registerFeature (f Feature ) {
4243 featuresLock .Lock ()
4344 defer featuresLock .Unlock ()
4445
45- if f == nil {
46- panic ("Feature cannot be nil" )
47- }
48-
49- if _ , ok := features [f .Name ()]; ok {
46+ if _ , ok := features .Get (f .Name ()); ok {
5047 panic ("Feature already registered" )
5148 }
5249
53- features [f .Name ()] = f
50+ features = append (features , f )
51+
52+ features .Sort ()
5453}
5554
5655var internalCMD = & cobra.Command {
@@ -67,8 +66,8 @@ func Iterate(iterator Iterator) {
6766 featuresLock .Lock ()
6867 defer featuresLock .Unlock ()
6968
70- for name , feature := range features {
71- iterator (name , feature )
69+ for _ , feature := range features {
70+ iterator (feature . Name () , feature )
7271 }
7372}
7473
@@ -130,6 +129,13 @@ func cmdRun(_ *cobra.Command, _ []string) {
130129 for _ , feature := range features {
131130 println (fmt .Sprintf ("Feature: %s" , feature .Name ()))
132131 println (fmt .Sprintf ("Description: %s" , feature .Description ()))
132+ if deps := feature .Dependencies (); len (deps ) > 0 {
133+ names := make ([]string , len (deps ))
134+ for id := range names {
135+ names [id ] = deps [id ].Name ()
136+ }
137+ println (fmt .Sprintf ("Dependencies: %s" , strings .Join (names , ", " )))
138+ }
133139 if feature .EnabledByDefault () {
134140 println ("Enabled: true" )
135141 } else {
@@ -155,6 +161,7 @@ func cmdRun(_ *cobra.Command, _ []string) {
155161
156162// Supported returns false when:
157163// - feature is disabled.
164+ // - any feature dependency is disabled.
158165// - a given version is lower than minimum feature version.
159166// - feature expects enterprise but a given enterprise arg is not true.
160167func Supported (f Feature , v driver.Version , enterprise bool ) bool {
@@ -167,6 +174,12 @@ func Supported(f Feature, v driver.Version, enterprise bool) bool {
167174 return false
168175 }
169176
177+ for _ , dependency := range f .Dependencies () {
178+ if ! Supported (dependency , v , enterprise ) {
179+ return false
180+ }
181+ }
182+
170183 return v .CompareTo (f .Version ()) >= 0
171184}
172185
0 commit comments