@@ -13,7 +13,10 @@ import (
1313 "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
1414)
1515
16- var identityFiles []string
16+ var (
17+ identityFiles []string
18+ newBlock bool
19+ )
1720
1821var sshCmd = & cobra.Command {
1922 Use : "ssh" ,
@@ -25,6 +28,7 @@ var sshCmd = &cobra.Command{
2528
2629func init () {
2730 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" )
2832 rootCmd .AddCommand (sshCmd )
2933}
3034
@@ -35,10 +39,11 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) {
3539
3640 sshArg := args [0 ]
3741 blockId := RpcContext .BlockId
38- if blockId == "" {
42+ if blockId == "" && ! newBlock {
3943 return fmt .Errorf ("cannot determine blockid (not in JWT)" )
4044 }
41- // first, make a connection independent of the block
45+
46+ // Create connection request
4247 connOpts := wshrpc.ConnRequest {
4348 Host : sshArg ,
4449 LogBlockId : blockId ,
@@ -48,7 +53,30 @@ func sshRun(cmd *cobra.Command, args []string) (rtnErr error) {
4853 }
4954 wshclient .ConnConnectCommand (RpcClient , connOpts , & wshrpc.RpcOpts {Timeout : 60000 })
5055
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
5280 data := wshrpc.CommandSetMetaData {
5381 ORef : waveobj .MakeORef (waveobj .OType_Block , blockId ),
5482 Meta : map [string ]any {
0 commit comments