-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
213 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
// Copyright 2024, Command Line Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/wavetermdev/thenextwave/pkg/remote" | ||
"github.com/wavetermdev/thenextwave/pkg/wshrpc" | ||
"github.com/wavetermdev/thenextwave/pkg/wshrpc/wshclient" | ||
) | ||
|
||
var connCmd = &cobra.Command{ | ||
Use: "conn [status|reinstall|disconnect|connect|ensure] [connection-name]", | ||
Short: "implements connection commands", | ||
Args: cobra.RangeArgs(1, 2), | ||
RunE: connRun, | ||
PreRunE: preRunSetupRpcClient, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(connCmd) | ||
} | ||
|
||
func connStatus() error { | ||
resp, err := wshclient.ConnStatusCommand(RpcClient, nil) | ||
if err != nil { | ||
return fmt.Errorf("getting connection status: %w", err) | ||
} | ||
if len(resp) == 0 { | ||
WriteStdout("no connections\n") | ||
return nil | ||
} | ||
WriteStdout("%-30s %-12s\n", "connection", "status") | ||
WriteStdout("----------------------------------------------\n") | ||
for _, conn := range resp { | ||
str := fmt.Sprintf("%-30s %-12s", conn.Connection, conn.Status) | ||
if conn.Error != "" { | ||
str += fmt.Sprintf(" (%s)", conn.Error) | ||
} | ||
str += "\n" | ||
WriteStdout("%s\n", str) | ||
} | ||
return nil | ||
} | ||
|
||
func connEnsure(connName string) error { | ||
err := wshclient.ConnEnsureCommand(RpcClient, connName, &wshrpc.RpcOpts{Timeout: 60000}) | ||
if err != nil { | ||
return fmt.Errorf("ensuring connection: %w", err) | ||
} | ||
WriteStdout("wsh ensured on connection %q\n", connName) | ||
return nil | ||
} | ||
|
||
func connReinstall(connName string) error { | ||
err := wshclient.ConnReinstallWshCommand(RpcClient, connName, &wshrpc.RpcOpts{Timeout: 60000}) | ||
if err != nil { | ||
return fmt.Errorf("reinstalling connection: %w", err) | ||
} | ||
WriteStdout("wsh reinstalled on connection %q\n", connName) | ||
return nil | ||
} | ||
|
||
func connDisconnect(connName string) error { | ||
err := wshclient.ConnDisconnectCommand(RpcClient, connName, &wshrpc.RpcOpts{Timeout: 10000}) | ||
if err != nil { | ||
return fmt.Errorf("disconnecting connection: %w", err) | ||
} | ||
WriteStdout("disconnected connection %q\n", connName) | ||
return nil | ||
} | ||
|
||
func connConnect(connName string) error { | ||
err := wshclient.ConnConnectCommand(RpcClient, connName, &wshrpc.RpcOpts{Timeout: 60000}) | ||
if err != nil { | ||
return fmt.Errorf("connecting connection: %w", err) | ||
} | ||
WriteStdout("connected connection %q\n", connName) | ||
return nil | ||
} | ||
|
||
func connRun(cmd *cobra.Command, args []string) error { | ||
connCmd := args[0] | ||
var connName string | ||
if connCmd != "status" { | ||
if len(args) < 2 { | ||
return fmt.Errorf("connection name is required") | ||
} | ||
connName = args[1] | ||
_, err := remote.ParseOpts(connName) | ||
if err != nil { | ||
return fmt.Errorf("cannot parse connection name: %w", err) | ||
} | ||
} | ||
if connCmd == "status" { | ||
return connStatus() | ||
} else if connCmd == "ensure" { | ||
return connEnsure(connName) | ||
} else if connCmd == "reinstall" { | ||
return connReinstall(connName) | ||
} else if connCmd == "disconnect" { | ||
return connDisconnect(connName) | ||
} else if connCmd == "connect" { | ||
return connConnect(connName) | ||
} else { | ||
return fmt.Errorf("unknown command %q", connCmd) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters