Skip to content
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
7 changes: 7 additions & 0 deletions internal/plugins/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ func (r *pluginResource) Execute(command resource.Command, row resource.Row) tea
}
}

if result.Terminal != nil {
return resource.LaunchTerminalMsg{
Command: result.Terminal.Command,
Args: result.Terminal.Args,
}
}

return nil
}
}
Expand Down
7 changes: 7 additions & 0 deletions pluginsdk/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,12 @@ func (r *grpcResource) Execute(ctx context.Context, command Command, row Row) (R
}
}

if response.Result.Terminal != nil {
result.Terminal = &Terminal{
Command: response.Result.Terminal.Command,
Args: response.Result.Terminal.Args,
}
}

return result, nil
}
11 changes: 9 additions & 2 deletions pluginsdk/grpc_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ func (s *grpcServer) Execute(ctx context.Context, request *pb.ExecuteRequest) (*
return nil, err
}

if result.Details != nil && result.Navigate != nil {
return nil, fmt.Errorf("plugin result cannot contain both details and navigation")
if err := result.isValid(); err != nil {
return nil, fmt.Errorf("invalid result: %w", err)
}

response := &pb.Result{}
Expand All @@ -158,6 +158,13 @@ func (s *grpcServer) Execute(ctx context.Context, request *pb.ExecuteRequest) (*
}
}

if result.Terminal != nil {
response.Terminal = &pb.Terminal{
Command: result.Terminal.Command,
Args: result.Terminal.Args,
}
}

return &pb.ExecuteResponse{Result: response}, nil
}

Expand Down
28 changes: 28 additions & 0 deletions pluginsdk/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pluginsdk
import (
"context"
"encoding/json"
"fmt"
)

type Client interface {
Expand Down Expand Up @@ -67,6 +68,7 @@ type Resource interface {
type Result struct {
Details *Details
Navigate *Navigate
Terminal *Terminal
}

type Details struct {
Expand All @@ -92,3 +94,29 @@ func Scope(ctx context.Context) map[string]string {
scope, _ := ctx.Value(scopeContextKey{}).(map[string]string)
return scope
}

type Terminal struct {
Command string
Args []string
}

func (r Result) isValid() error {
actions := 0
if r.Details != nil {
actions++
}

if r.Navigate != nil {
actions++
}

if r.Terminal != nil {
actions++
}

if actions > 1 {
return fmt.Errorf("plugin result cannot contain multiple actions")
}

return nil
}
126 changes: 96 additions & 30 deletions pluginsdk/proto/plugin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion pluginsdk/proto/plugin.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

syntax = "proto3";

package o7k.plugin.v1;
Expand Down Expand Up @@ -91,6 +92,7 @@ message ExecuteResponse {
message Result {
Details details = 1;
Navigate navigate = 2;
Terminal terminal = 3;
}

message Details {
Expand All @@ -104,4 +106,9 @@ message Navigate {
string field = 3;
string value = 4;
map<string, string> scope = 5;
}
}

message Terminal {
string command = 1;
repeated string args = 2;
}
Loading