@@ -13,7 +13,10 @@ import (
13
13
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
14
14
)
15
15
16
- var identityFiles []string
16
+ var (
17
+ identityFiles []string
18
+ newBlock bool
19
+ )
17
20
18
21
var sshCmd = & cobra.Command {
19
22
Use : "ssh" ,
@@ -25,6 +28,7 @@ var sshCmd = &cobra.Command{
25
28
26
29
func init () {
27
30
sshCmd .Flags ().StringArrayVarP (& identityFiles , "identityfile" , "i" , []string {}, "add an identity file for publickey authentication" )
31
+ sshCmd .Flags ().BoolVarP (& newBlock , "new" , "n" , false , "create a new terminal block with this connection" )
28
32
rootCmd .AddCommand (sshCmd )
29
33
}
30
34
@@ -35,10 +39,11 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) {
35
39
36
40
sshArg := args [0 ]
37
41
blockId := RpcContext .BlockId
38
- if blockId == "" {
42
+ if blockId == "" && ! newBlock {
39
43
return fmt .Errorf ("cannot determine blockid (not in JWT)" )
40
44
}
41
- // first, make a connection independent of the block
45
+
46
+ // Create connection request
42
47
connOpts := wshrpc.ConnRequest {
43
48
Host : sshArg ,
44
49
LogBlockId : blockId ,
@@ -48,7 +53,30 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) {
48
53
}
49
54
wshclient .ConnConnectCommand (RpcClient , connOpts , & wshrpc.RpcOpts {Timeout : 60000 })
50
55
51
- // now, with that made, it will be straightforward to connect
56
+ if newBlock {
57
+ // Create a new block with the SSH connection
58
+ createMeta := map [string ]any {
59
+ waveobj .MetaKey_View : "term" ,
60
+ waveobj .MetaKey_Controller : "shell" ,
61
+ waveobj .MetaKey_Connection : sshArg ,
62
+ }
63
+ if RpcContext .Conn != "" {
64
+ createMeta [waveobj .MetaKey_Connection ] = RpcContext .Conn
65
+ }
66
+ createBlockData := wshrpc.CommandCreateBlockData {
67
+ BlockDef : & waveobj.BlockDef {
68
+ Meta : createMeta ,
69
+ },
70
+ }
71
+ oref , err := wshclient .CreateBlockCommand (RpcClient , createBlockData , nil )
72
+ if err != nil {
73
+ return fmt .Errorf ("creating new terminal block: %w" , err )
74
+ }
75
+ WriteStdout ("new terminal block created with connection to %q: %s\n " , sshArg , oref )
76
+ return nil
77
+ }
78
+
79
+ // Update existing block with the new connection
52
80
data := wshrpc.CommandSetMetaData {
53
81
ORef : waveobj .MakeORef (waveobj .OType_Block , blockId ),
54
82
Meta : map [string ]any {
0 commit comments