Skip to content

Commit

Permalink
port forwarding
Browse files Browse the repository at this point in the history
  • Loading branch information
Anish Maddipoti authored and Anish Maddipoti committed Jul 9, 2024
1 parent 68f9e16 commit 83e30b8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions pkg/cmd/portforward/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type PortforwardStore interface {

func NewCmdPortForwardSSH(pfStore PortforwardStore, t *terminal.Terminal) *cobra.Command {
var port string
var useHost bool
cmd := &cobra.Command{
Annotations: map[string]string{"ssh": ""},
Use: "port-forward",
Expand All @@ -44,14 +45,15 @@ func NewCmdPortForwardSSH(pfStore PortforwardStore, t *terminal.Terminal) *cobra
if port == "" {
port = startInput(t)
}
err := RunPortforward(pfStore, args[0], port)
err := RunPortforward(pfStore, args[0], port. useHost)

Check failure on line 48 in pkg/cmd/portforward/portforward.go

View workflow job for this annotation

GitHub Actions / release-test

not enough arguments in call to RunPortforward

Check failure on line 48 in pkg/cmd/portforward/portforward.go

View workflow job for this annotation

GitHub Actions / release-test

port.useHost undefined (type string has no field or method useHost)

Check failure on line 48 in pkg/cmd/portforward/portforward.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

not enough arguments in call to RunPortforward

Check failure on line 48 in pkg/cmd/portforward/portforward.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

port.useHost undefined (type string has no field or method useHost)

Check failure on line 48 in pkg/cmd/portforward/portforward.go

View workflow job for this annotation

GitHub Actions / ci (ubuntu-20.04)

not enough arguments in call to RunPortforward

Check failure on line 48 in pkg/cmd/portforward/portforward.go

View workflow job for this annotation

GitHub Actions / ci (ubuntu-20.04)

port.useHost undefined (type string has no field or method useHost)
if err != nil {
return breverrors.WrapAndTrace(err)
}
return nil
},
}
cmd.Flags().StringVarP(&port, "port", "p", "", "port forward flag describe me better")
cmd.Flags().BoolVar(&useHost, "host", false, "Use the -host version of the instance")
err := cmd.RegisterFlagCompletionFunc("port", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoSpace
})
Expand All @@ -63,7 +65,7 @@ func NewCmdPortForwardSSH(pfStore PortforwardStore, t *terminal.Terminal) *cobra
return cmd
}

func RunPortforward(pfStore PortforwardStore, nameOrID string, portString string) error {
func RunPortforward(pfStore PortforwardStore, nameOrID string, portString string, useHost bool) error {
var portSplit []string
if strings.Contains(portString, ":") {
portSplit = strings.Split(portString, ":")
Expand All @@ -76,7 +78,7 @@ func RunPortforward(pfStore PortforwardStore, nameOrID string, portString string

res := refresh.RunRefreshAsync(pfStore)

sshName, err := ConvertNametoSSHName(pfStore, nameOrID)
sshName, err := ConvertNametoSSHName(pfStore, nameOrID, useHost)
if err != nil {
return breverrors.WrapAndTrace(err)
}
Expand All @@ -93,12 +95,15 @@ func RunPortforward(pfStore PortforwardStore, nameOrID string, portString string
return nil
}

func ConvertNametoSSHName(store PortforwardStore, workspaceNameOrID string) (string, error) {
func ConvertNametoSSHName(store PortforwardStore, workspaceNameOrID string, useHost bool) (string, error) {
workspace, err := util.GetUserWorkspaceByNameOrIDErr(store, workspaceNameOrID)
if err != nil {
return "", breverrors.WrapAndTrace(err)
}
sshName := string(workspace.GetLocalIdentifier())
if useHost {
sshName += "-host"
}
return sshName, nil
}

Expand Down

0 comments on commit 83e30b8

Please sign in to comment.