Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin): initialize logger #6836

Merged
merged 1 commit into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cmd/trivy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ func main() {
func run() error {
// Trivy behaves as the specified plugin.
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 nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,7 @@ func NewPluginCommand() *cobra.Command {
Short: "Run a plugin on the fly",
Args: cobra.MinimumNArgs(1),
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{
Expand Down
8 changes: 4 additions & 4 deletions pkg/plugin/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
return defaultManager().Start(ctx, name, opts)
}
func RunWithURL(ctx context.Context, name string, opts Options) error {
return defaultManager().RunWithURL(ctx, name, opts)
func Run(ctx context.Context, name string, opts Options) error {
return defaultManager().Run(ctx, name, opts)
}
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) }
Expand Down Expand Up @@ -291,8 +291,8 @@ func (m *Manager) Start(ctx context.Context, name string, opts Options) (Wait, e
return wait, nil
}

// RunWithURL runs the plugin
func (m *Manager) RunWithURL(ctx context.Context, name string, opts Options) error {
// Run installs and runs the plugin
func (m *Manager) Run(ctx context.Context, name string, opts Options) error {
plugin, err := m.Install(ctx, name, opts)
if err != nil {
return xerrors.Errorf("plugin install error: %w", err)
Expand Down