Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add port prompt for compute init #203

Merged
merged 5 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/app/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ COMMANDS
package
--backend=BACKEND A hostname, IPv4, or IPv6 address for the
package backend
--backend-port=BACKEND-PORT
A port number for the package backend

compute build [<flags>]
Build a Compute@Edge package locally
Expand Down
41 changes: 30 additions & 11 deletions pkg/compute/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,16 @@ type StarterKit struct {
// InitCommand initializes a Compute@Edge project package on the local machine.
type InitCommand struct {
common.Base
client api.HTTPClient
manifest manifest.Data
language string
from string
branch string
tag string
path string
domain string
backend string
client api.HTTPClient
manifest manifest.Data
language string
from string
branch string
tag string
path string
domain string
backend string
backendPort uint
}

// NewInitCommand returns a usable command registered under the parent.
Expand All @@ -96,8 +97,9 @@ func NewInitCommand(parent common.Registerer, client api.HTTPClient, globals *co
c.CmdClause.Flag("branch", "Git branch name to clone from package template repository").Hidden().StringVar(&c.branch)
c.CmdClause.Flag("tag", "Git tag name to clone from package template repository").Hidden().StringVar(&c.tag)
c.CmdClause.Flag("path", "Destination to write the new package, defaulting to the current directory").Short('p').StringVar(&c.path)
c.CmdClause.Flag("domain", "The name of the domain associated to the package").StringVar(&c.path)
c.CmdClause.Flag("backend", "A hostname, IPv4, or IPv6 address for the package backend").StringVar(&c.path)
c.CmdClause.Flag("domain", "The name of the domain associated to the package").StringVar(&c.domain)
c.CmdClause.Flag("backend", "A hostname, IPv4, or IPv6 address for the package backend").StringVar(&c.backend)
Comment on lines +100 to +101
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed these flags were assigning values to the wrong variable 🤦🏻 so have fixed in this PR.

c.CmdClause.Flag("backend-port", "A port number for the package backend").UintVar(&c.backendPort)

return &c
}
Expand Down Expand Up @@ -293,9 +295,25 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
}
if c.backend == "" || c.backend == "originless" {
c.backend = "127.0.0.1"
c.backendPort = uint(80)
}
}

if c.backendPort == 0 {
input, err := text.Input(out, "Backend port number: [80] ", in)
if err != nil {
return fmt.Errorf("error reading input %w", err)
}

portnumber, err := strconv.Atoi(input)
if err != nil {
text.Warning(out, "error converting input: %v. We'll use the default port number: [80].", err)
portnumber = 80
}

c.backendPort = uint(portnumber)
}

text.Break(out)

if !c.Globals.Verbose() {
Expand Down Expand Up @@ -370,6 +388,7 @@ func (c *InitCommand) Exec(in io.Reader, out io.Writer) (err error) {
ServiceVersion: version,
Name: c.backend,
Address: c.backend,
Port: c.backendPort,
})
if err != nil {
return fmt.Errorf("error creating backend: %w", err)
Expand Down