-
-
Notifications
You must be signed in to change notification settings - Fork 512
/
command_remote.go
40 lines (35 loc) · 1.27 KB
/
command_remote.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cli
import (
"context"
"fmt"
"os"
"github.com/spf13/cobra"
empty "google.golang.org/protobuf/types/known/emptypb"
"github.com/telepresenceio/telepresence/rpc/v2/connector"
"github.com/telepresenceio/telepresence/rpc/v2/daemon"
"github.com/telepresenceio/telepresence/v2/pkg/client/cli/cliutil"
)
func getRemoteCommands(ctx context.Context) (groups cliutil.CommandGroups, err error) {
err = cliutil.WithStartedConnector(ctx, false, func(ctx context.Context, connectorClient connector.ConnectorClient) error {
remote, err := connectorClient.ListCommands(ctx, &empty.Empty{})
if err != nil {
return fmt.Errorf("unable to call ListCommands: %w", err)
}
groups, err = cliutil.RPCToCommands(remote, runRemote)
return err
})
return
}
func runRemote(cmd *cobra.Command, _ []string) error {
return cliutil.WithNetwork(cmd.Context(), func(ctx context.Context, _ daemon.DaemonClient) error {
return cliutil.WithConnector(ctx, func(ctx context.Context, connectorClient connector.ConnectorClient) error {
result, err := connectorClient.RunCommand(ctx, &connector.RunCommandRequest{OsArgs: os.Args[1:]})
if err != nil {
return err
}
_, _ = cmd.OutOrStdout().Write(result.GetStdout())
_, _ = cmd.ErrOrStderr().Write(result.GetStderr())
return nil
})
})
}