ports

package
v0.12.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2024 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PortForwardCmd = &cobra.Command{
	Use:   "forward [PORT]",
	Short: "Forward a port from a project to your local machine",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		port, err := strconv.Atoi(args[0])
		if err != nil {
			log.Fatal(err)
		}

		if len(args) > 1 {
			workspace, err := server.GetWorkspace(args[1])
			if err != nil {
				log.Fatal(err)
			}
			workspaceId = *workspace.Id
		}

		if len(args) == 3 {
			projectName = args[2]
		} else {
			projectName, err = server.GetFirstWorkspaceProjectName(workspaceId, projectName, nil)
			if err != nil {
				log.Fatal(err)
			}
		}

		hostPort, errChan := ports.ForwardPort(workspaceId, projectName, uint16(port))

		if hostPort == nil {
			if err = <-errChan; err != nil {
				log.Fatal(err)
			}
		} else {
			if *hostPort != uint16(port) {
				view_util.RenderInfoMessage(fmt.Sprintf("Port %d already in use.", port))
			}
			view_util.RenderInfoMessage(fmt.Sprintf("Port available at http://localhost:%d\n", *hostPort))
		}

		if publicPreview {
			go func() {
				errChan <- forwardPublicPort(workspaceId, projectName, *hostPort, uint16(port))
			}()
		}

		for {
			err := <-errChan
			if err != nil {
				log.Debug(err)
			}
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL