This repository was archived by the owner on Jan 21, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +45
-1
lines changed Expand file tree Collapse file tree 5 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,14 @@ func flavorPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
28
28
name := cmd .PersistentFlags ().String ("name" , "" , "Name of plugin" )
29
29
30
30
cmd .PersistentPreRunE = func (c * cobra.Command , args []string ) error {
31
+ if err := upTree (c , func (x * cobra.Command , argv []string ) error {
32
+ if x .PersistentPreRunE != nil {
33
+ return x .PersistentPreRunE (x , argv )
34
+ }
35
+ return nil
36
+ }); err != nil {
37
+ return err
38
+ }
31
39
32
40
endpoint , err := plugins ().Find (plugin .Name (* name ))
33
41
if err != nil {
Original file line number Diff line number Diff line change @@ -31,6 +31,14 @@ func groupPluginCommand(plugins func() discovery.Plugins) *cobra.Command {
31
31
}
32
32
name := cmd .PersistentFlags ().String ("name" , DefaultGroupPluginName , "Name of plugin" )
33
33
cmd .PersistentPreRunE = func (c * cobra.Command , args []string ) error {
34
+ if err := upTree (c , func (x * cobra.Command , argv []string ) error {
35
+ if x .PersistentPreRunE != nil {
36
+ return x .PersistentPreRunE (x , argv )
37
+ }
38
+ return nil
39
+ }); err != nil {
40
+ return err
41
+ }
34
42
35
43
endpoint , err := plugins ().Find (plugin .Name (* name ))
36
44
if err != nil {
Original file line number Diff line number Diff line change @@ -26,6 +26,14 @@ func instancePluginCommand(plugins func() discovery.Plugins) *cobra.Command {
26
26
}
27
27
name := cmd .PersistentFlags ().String ("name" , "" , "Name of plugin" )
28
28
cmd .PersistentPreRunE = func (c * cobra.Command , args []string ) error {
29
+ if err := upTree (c , func (x * cobra.Command , argv []string ) error {
30
+ if x .PersistentPreRunE != nil {
31
+ return x .PersistentPreRunE (x , argv )
32
+ }
33
+ return nil
34
+ }); err != nil {
35
+ return err
36
+ }
29
37
30
38
endpoint , err := plugins ().Find (plugin .Name (* name ))
31
39
if err != nil {
Original file line number Diff line number Diff line change @@ -19,8 +19,9 @@ func main() {
19
19
Short : "infrakit cli" ,
20
20
}
21
21
logLevel := cmd .PersistentFlags ().Int ("log" , cli .DefaultLogLevel , "Logging level. 0 is least verbose. Max is 5" )
22
- cmd .PersistentPreRun = func (c * cobra.Command , args []string ) {
22
+ cmd .PersistentPreRunE = func (c * cobra.Command , args []string ) error {
23
23
cli .SetLogLevel (* logLevel )
24
+ return nil
24
25
}
25
26
26
27
// Don't print usage text for any error returned from a RunE function. Only print it when explicitly requested.
@@ -57,3 +58,14 @@ func assertNotNil(message string, f interface{}) {
57
58
os .Exit (1 )
58
59
}
59
60
}
61
+
62
+ // upTree traverses up the command tree and starts executing the do function in the order from top
63
+ // of the command tree to the bottom. Cobra commands executes only one level of PersistentPreRunE
64
+ // in reverse order. This breaks our model of setting log levels at the very top and have the log level
65
+ // set throughout the entire hierarchy of command execution.
66
+ func upTree (c * cobra.Command , do func (* cobra.Command , []string ) error ) error {
67
+ if p := c .Parent (); p != nil {
68
+ return upTree (p , do )
69
+ }
70
+ return do (c , c .Flags ().Args ())
71
+ }
Original file line number Diff line number Diff line change @@ -27,6 +27,14 @@ func managerCommand(plugins func() discovery.Plugins) *cobra.Command {
27
27
Short : "Access the manager" ,
28
28
}
29
29
cmd .PersistentPreRunE = func (c * cobra.Command , args []string ) error {
30
+ if err := upTree (c , func (x * cobra.Command , argv []string ) error {
31
+ if x .PersistentPreRunE != nil {
32
+ return x .PersistentPreRunE (x , argv )
33
+ }
34
+ return nil
35
+ }); err != nil {
36
+ return err
37
+ }
30
38
31
39
// Scan for a manager
32
40
pm , err := plugins ().List ()
You can’t perform that action at this time.
0 commit comments