@@ -62,6 +62,7 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.{{e
62
62
63
63
// NewApp is the factory method to return Trivy CLI
64
64
func NewApp () * cobra.Command {
65
+ cobra .EnableTraverseRunHooks = true // To execute persistent pre-run hooks from all parents.
65
66
globalFlags := flag .NewGlobalFlagGroup ()
66
67
rootCmd := NewRootCommand (globalFlags )
67
68
rootCmd .AddGroup (
@@ -89,7 +90,7 @@ func NewApp() *cobra.Command {
89
90
NewServerCommand (globalFlags ),
90
91
NewConfigCommand (globalFlags ),
91
92
NewConvertCommand (globalFlags ),
92
- NewPluginCommand (),
93
+ NewPluginCommand (globalFlags ),
93
94
NewModuleCommand (globalFlags ),
94
95
NewKubernetesCommand (globalFlags ),
95
96
NewSBOMCommand (globalFlags ),
@@ -719,14 +720,25 @@ func NewConfigCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
719
720
return cmd
720
721
}
721
722
722
- func NewPluginCommand () * cobra.Command {
723
+ func NewPluginCommand (globalFlags * flag.GlobalFlagGroup ) * cobra.Command {
724
+ var pluginOptions flag.Options
725
+ pluginFlags := & flag.Flags {
726
+ GlobalFlagGroup : globalFlags ,
727
+ }
723
728
cmd := & cobra.Command {
724
729
Use : "plugin subcommand" ,
725
730
Aliases : []string {"p" },
726
731
GroupID : groupManagement ,
727
732
Short : "Manage plugins" ,
728
733
SilenceErrors : true ,
729
734
SilenceUsage : true ,
735
+ PersistentPreRunE : func (cmd * cobra.Command , args []string ) (err error ) {
736
+ pluginOptions , err = pluginFlags .ToOptions (args )
737
+ if err != nil {
738
+ return err
739
+ }
740
+ return nil
741
+ },
730
742
}
731
743
cmd .AddCommand (
732
744
& cobra.Command {
@@ -746,7 +758,7 @@ func NewPluginCommand() *cobra.Command {
746
758
DisableFlagsInUseLine : true ,
747
759
Args : cobra .ExactArgs (1 ),
748
760
RunE : func (cmd * cobra.Command , args []string ) error {
749
- if _ , err := plugin .Install (cmd .Context (), args [0 ], plugin.Options {}); err != nil {
761
+ if _ , err := plugin .Install (cmd .Context (), args [0 ], plugin.Options {Insecure : pluginOptions . Insecure }); err != nil {
750
762
return xerrors .Errorf ("plugin install error: %w" , err )
751
763
}
752
764
return nil
@@ -805,7 +817,10 @@ func NewPluginCommand() *cobra.Command {
805
817
Short : "Run a plugin on the fly" ,
806
818
Args : cobra .MinimumNArgs (1 ),
807
819
RunE : func (cmd * cobra.Command , args []string ) error {
808
- return plugin .Run (cmd .Context (), args [0 ], plugin.Options {Args : args [1 :]})
820
+ return plugin .Run (cmd .Context (), args [0 ], plugin.Options {
821
+ Args : args [1 :],
822
+ Insecure : pluginOptions .Insecure ,
823
+ })
809
824
},
810
825
},
811
826
& cobra.Command {
@@ -816,7 +831,7 @@ func NewPluginCommand() *cobra.Command {
816
831
SilenceUsage : true ,
817
832
Args : cobra .NoArgs ,
818
833
RunE : func (cmd * cobra.Command , _ []string ) error {
819
- if err := plugin .Update (cmd .Context ()); err != nil {
834
+ if err := plugin .Update (cmd .Context (), plugin. Options { Insecure : pluginOptions . Insecure } ); err != nil {
820
835
return xerrors .Errorf ("plugin update error: %w" , err )
821
836
}
822
837
return nil
0 commit comments