Merge branch 'main' into main-style

This commit is contained in:
Alan Donovan 2021-08-27 17:30:34 -04:00
commit 9f082ca887
3 changed files with 25 additions and 10 deletions

View file

@ -57,8 +57,9 @@ func code(codespaceName string, useInsiders bool) error {
codespaceName = codespace.Name
}
if err := open.Run(vscodeProtocolURL(codespaceName, useInsiders)); err != nil {
return fmt.Errorf("error opening vscode URL")
url := vscodeProtocolURL(codespaceName, useInsiders)
if err := open.Run(url); err != nil {
return fmt.Errorf("error opening vscode URL %s: %s. (Is VSCode installed?)", url, err)
}
return nil

View file

@ -126,11 +126,11 @@ func getRepoName() (string, error) {
repoSurvey := []*survey.Question{
{
Name: "repository",
Prompt: &survey.Input{Message: "Repository"},
Prompt: &survey.Input{Message: "Repository:"},
Validate: survey.Required,
},
}
err := survey.Ask(repoSurvey, &repo)
err := ask(repoSurvey, &repo)
return repo, err
}
@ -142,11 +142,11 @@ func getBranchName() (string, error) {
branchSurvey := []*survey.Question{
{
Name: "branch",
Prompt: &survey.Input{Message: "Branch"},
Prompt: &survey.Input{Message: "Branch:"},
Validate: survey.Required,
},
}
err := survey.Ask(branchSurvey, &branch)
err := ask(branchSurvey, &branch)
return branch, err
}
@ -198,7 +198,7 @@ func getMachineName(ctx context.Context, user *api.User, repo *api.Repository, l
}
skuAnswers := struct{ SKU string }{}
if err := survey.Ask(skuSurvey, &skuAnswers); err != nil {
if err := ask(skuSurvey, &skuAnswers); err != nil {
return "", fmt.Errorf("error getting SKU: %v", err)
}
@ -207,3 +207,8 @@ func getMachineName(ctx context.Context, user *api.User, repo *api.Repository, l
return machine, nil
}
// ask asks survery questions using standard options.
func ask(qs []*survey.Question, response interface{}) error {
return survey.Ask(qs, response, survey.WithShowCursor(true))
}

View file

@ -19,11 +19,17 @@ 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 Cobra "ports" command that displays a table of available ports,
// according to the specified flags.
func newPortsCmd() *cobra.Command {
opts := &portsOptions{}
@ -88,7 +94,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
@ -101,7 +107,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),
})
@ -169,6 +174,7 @@ func getDevContainer(ctx context.Context, apiClient *api.API, codespace *api.Cod
return ch
}
// newPortsPublicCmd returns a Cobra "ports public" subcommand, which makes a given port public.
func newPortsPublicCmd() *cobra.Command {
return &cobra.Command{
Use: "public <codespace> <port>",
@ -181,6 +187,7 @@ func newPortsPublicCmd() *cobra.Command {
}
}
// newPortsPrivateCmd returns a Cobra "ports private" subcommand, which makes a given port private.
func newPortsPrivateCmd() *cobra.Command {
return &cobra.Command{
Use: "private <codespace> <port>",
@ -240,6 +247,8 @@ func updatePortVisibility(log *output.Logger, codespaceName, sourcePort string,
return nil
}
// 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 <codespace> <source-port>:<destination-port>",