mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 07:10:41 -08:00
fix(plugin): initialize logger (#6836)
Signed-off-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
@@ -28,7 +28,8 @@ func main() {
|
|||||||
func run() error {
|
func run() error {
|
||||||
// Trivy behaves as the specified plugin.
|
// Trivy behaves as the specified plugin.
|
||||||
if runAsPlugin := os.Getenv("TRIVY_RUN_AS_PLUGIN"); runAsPlugin != "" {
|
if runAsPlugin := os.Getenv("TRIVY_RUN_AS_PLUGIN"); runAsPlugin != "" {
|
||||||
if err := plugin.RunWithURL(context.Background(), runAsPlugin, plugin.Options{Args: os.Args[1:]}); err != nil {
|
log.InitLogger(false, false)
|
||||||
|
if err := plugin.Run(context.Background(), runAsPlugin, plugin.Options{Args: os.Args[1:]}); err != nil {
|
||||||
return xerrors.Errorf("plugin error: %w", err)
|
return xerrors.Errorf("plugin error: %w", err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -799,7 +799,7 @@ func NewPluginCommand() *cobra.Command {
|
|||||||
Short: "Run a plugin on the fly",
|
Short: "Run a plugin on the fly",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return plugin.RunWithURL(cmd.Context(), args[0], plugin.Options{Args: args[1:]})
|
return plugin.Run(cmd.Context(), args[0], plugin.Options{Args: args[1:]})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&cobra.Command{
|
&cobra.Command{
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ func Install(ctx context.Context, name string, opts Options) (Plugin, error) {
|
|||||||
func Start(ctx context.Context, name string, opts Options) (Wait, error) {
|
func Start(ctx context.Context, name string, opts Options) (Wait, error) {
|
||||||
return defaultManager().Start(ctx, name, opts)
|
return defaultManager().Start(ctx, name, opts)
|
||||||
}
|
}
|
||||||
func RunWithURL(ctx context.Context, name string, opts Options) error {
|
func Run(ctx context.Context, name string, opts Options) error {
|
||||||
return defaultManager().RunWithURL(ctx, name, opts)
|
return defaultManager().Run(ctx, name, opts)
|
||||||
}
|
}
|
||||||
func Upgrade(ctx context.Context, names []string) error { return defaultManager().Upgrade(ctx, names) }
|
func Upgrade(ctx context.Context, names []string) error { return defaultManager().Upgrade(ctx, names) }
|
||||||
func Uninstall(ctx context.Context, name string) error { return defaultManager().Uninstall(ctx, name) }
|
func Uninstall(ctx context.Context, name string) error { return defaultManager().Uninstall(ctx, name) }
|
||||||
@@ -291,8 +291,8 @@ func (m *Manager) Start(ctx context.Context, name string, opts Options) (Wait, e
|
|||||||
return wait, nil
|
return wait, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunWithURL runs the plugin
|
// Run installs and runs the plugin
|
||||||
func (m *Manager) RunWithURL(ctx context.Context, name string, opts Options) error {
|
func (m *Manager) Run(ctx context.Context, name string, opts Options) error {
|
||||||
plugin, err := m.Install(ctx, name, opts)
|
plugin, err := m.Install(ctx, name, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xerrors.Errorf("plugin install error: %w", err)
|
return xerrors.Errorf("plugin install error: %w", err)
|
||||||
|
|||||||
Reference in New Issue
Block a user