From 3dcee5cca72f0a70aed7cdc270cd4a0d6f0d584b Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Fri, 27 Aug 2021 12:41:36 +0000 Subject: [PATCH 1/3] remove dst port column and add docs --- cmd/ghcs/ports.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/ghcs/ports.go b/cmd/ghcs/ports.go index 09397af54..9e2713a5e 100644 --- a/cmd/ghcs/ports.go +++ b/cmd/ghcs/ports.go @@ -19,11 +19,16 @@ import ( "golang.org/x/sync/errgroup" ) +// PortOptions represents the options accepted by the ports command. type PortsOptions struct { + // CodespaceName is the name of the codespace, optional CodespaceName string - AsJSON bool + + // AsJSON dictates whether the command returns a json output or not, optional + AsJSON bool } +// NewPortsCmd returns a new cobra command representing the ports command and sub commands func NewPortsCmd() *cobra.Command { opts := &PortsOptions{} @@ -50,6 +55,7 @@ func init() { rootCmd.AddCommand(NewPortsCmd()) } +// Ports accepts a PortOptions pointer and logs a list the list of available open ports found in a codespace func Ports(opts *PortsOptions) error { apiClient := api.New(os.Getenv("GITHUB_TOKEN")) ctx := context.Background() @@ -87,7 +93,7 @@ func Ports(opts *PortsOptions) error { } table := output.NewTable(os.Stdout, opts.AsJSON) - table.SetHeader([]string{"Label", "Source Port", "Destination Port", "Public", "Browse URL"}) + table.SetHeader([]string{"Label", "Port", "Public", "Browse URL"}) for _, port := range ports { sourcePort := strconv.Itoa(port.SourcePort) var portName string @@ -100,7 +106,6 @@ func Ports(opts *PortsOptions) error { table.Append([]string{ portName, sourcePort, - strconv.Itoa(port.DestinationPort), strings.ToUpper(strconv.FormatBool(port.IsPublic)), fmt.Sprintf("https://%s-%s.githubpreview.dev/", codespace.Name, sourcePort), }) @@ -168,6 +173,8 @@ func getDevContainer(ctx context.Context, apiClient *api.API, codespace *api.Cod return ch } +// NewPortsPublicCmd returns a cobra command representing the ports subcommand used +// to make a given port public func NewPortsPublicCmd() *cobra.Command { return &cobra.Command{ Use: "public ", @@ -180,6 +187,8 @@ func NewPortsPublicCmd() *cobra.Command { } } +// NewPortsPrivateCmd rturns a cobra command representing the ports subcommand used +// to make a given port private func NewPortsPrivateCmd() *cobra.Command { return &cobra.Command{ Use: "private ", @@ -239,6 +248,8 @@ func updatePortVisibility(log *output.Logger, codespaceName, sourcePort string, return nil } +// NewPortsForwardCmd returns a cobra command representing the ports subcommand used to forward +// ports from the codespace to localhost, it supports multiple ports to be forwarded at once func NewPortsForwardCmd() *cobra.Command { return &cobra.Command{ Use: "forward :", From 5dc923777be8c5ca232128c2b7924420b49b6bfd Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Fri, 27 Aug 2021 15:32:18 +0000 Subject: [PATCH 2/3] update docs, make ports private to be more consistent --- cmd/ghcs/ports.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/ghcs/ports.go b/cmd/ghcs/ports.go index 9e2713a5e..2318097aa 100644 --- a/cmd/ghcs/ports.go +++ b/cmd/ghcs/ports.go @@ -21,14 +21,15 @@ import ( // PortOptions represents the options accepted by the ports command. type PortsOptions struct { - // CodespaceName is the name of the codespace, optional + // CodespaceName is the name of the codespace, optional. CodespaceName string - // AsJSON dictates whether the command returns a json output or not, optional + // AsJSON dictates whether the command returns a json output or not, optional. AsJSON bool } -// NewPortsCmd returns a new cobra command representing the ports command and sub commands +// NewPortsCmd returns a Cobra "ports" command that displays a table of available ports, +// according to the specified flags. func NewPortsCmd() *cobra.Command { opts := &PortsOptions{} @@ -37,7 +38,7 @@ func NewPortsCmd() *cobra.Command { Short: "List ports in a Codespace", Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { - return Ports(opts) + return ports(opts) }, } @@ -55,8 +56,7 @@ func init() { rootCmd.AddCommand(NewPortsCmd()) } -// Ports accepts a PortOptions pointer and logs a list the list of available open ports found in a codespace -func Ports(opts *PortsOptions) error { +func ports(opts *PortsOptions) error { apiClient := api.New(os.Getenv("GITHUB_TOKEN")) ctx := context.Background() log := output.NewLogger(os.Stdout, os.Stderr, opts.AsJSON) @@ -173,7 +173,7 @@ func getDevContainer(ctx context.Context, apiClient *api.API, codespace *api.Cod return ch } -// NewPortsPublicCmd returns a cobra command representing the ports subcommand used +// NewPortsPublicCmd returns a Cobra "ports public" subcommand, which makes a given port public. // to make a given port public func NewPortsPublicCmd() *cobra.Command { return &cobra.Command{ @@ -187,8 +187,7 @@ func NewPortsPublicCmd() *cobra.Command { } } -// NewPortsPrivateCmd rturns a cobra command representing the ports subcommand used -// to make a given port private +// NewPortsPrivateCmd returns a Cobra "ports private" subcommand, which makes a given port private. func NewPortsPrivateCmd() *cobra.Command { return &cobra.Command{ Use: "private ", @@ -248,8 +247,8 @@ func updatePortVisibility(log *output.Logger, codespaceName, sourcePort string, return nil } -// NewPortsForwardCmd returns a cobra command representing the ports subcommand used to forward -// ports from the codespace to localhost, it supports multiple ports to be forwarded at once +// NewPortsForwardCmd returns a Cobra "ports forward" subcommand, which forwards a set of +// port pairs from the codespace to localhost. func NewPortsForwardCmd() *cobra.Command { return &cobra.Command{ Use: "forward :", From 8e95493872f31e953a33a86381e12ab93f7999f5 Mon Sep 17 00:00:00 2001 From: Jose Garcia Date: Fri, 27 Aug 2021 15:46:40 +0000 Subject: [PATCH 3/3] period --- cmd/ghcs/ports.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/ghcs/ports.go b/cmd/ghcs/ports.go index 2318097aa..ea501b73e 100644 --- a/cmd/ghcs/ports.go +++ b/cmd/ghcs/ports.go @@ -174,7 +174,7 @@ func getDevContainer(ctx context.Context, apiClient *api.API, codespace *api.Cod } // NewPortsPublicCmd returns a Cobra "ports public" subcommand, which makes a given port public. -// to make a given port public +// to make a given port public. func NewPortsPublicCmd() *cobra.Command { return &cobra.Command{ Use: "public ",