Skip to content

Commit

Permalink
Add builtins and list command updated tables
Browse files Browse the repository at this point in the history
  • Loading branch information
codepope committed Aug 10, 2020
1 parent 6656824 commit b88c1f1
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 14 deletions.
19 changes: 14 additions & 5 deletions builtinsupport/builtinsupport.go
Expand Up @@ -5,6 +5,7 @@ import "fmt"
type Builtin struct {
Name string
Description string
Details string
FileText string
}

Expand Down Expand Up @@ -47,7 +48,9 @@ func initBuiltins() {

var basicbuiltins = []Builtin{
Builtin{Name: "node",
Description: "Builtin Nodejs",
Description: "Nodejs builtin",
Details: `Requires package.json, package-lock.json. Runs a production npm install
and copies all files across. When run will call npm start to start the application.`,
FileText: `
FROM node:current-alpine
WORKDIR /app
Expand All @@ -59,7 +62,9 @@ var basicbuiltins = []Builtin{
CMD [ "npm","start" ]
`},
Builtin{Name: "ruby",
Description: "Builtin Ruby - runs app.rb",
Description: "Ruby builtin",
Details: `Builtin for a Ruby application with a Gemfile. Runs bundle install to build.
At runtime, it uses rackup to run app.rb`,
FileText: `
FROM ruby:2.7
WORKDIR /usr/src/app
Expand All @@ -71,7 +76,9 @@ var basicbuiltins = []Builtin{
CMD ["bundle", "exec", "rackup", "--host", "0.0.0.0", "-p", "8080"]
`},
Builtin{Name: "deno",
Description: "Builtin Deno - runs main.ts, requires deps.ts",
Description: "Deno builtin",
Details: `Uses Alpine image from https://github.com/hayd/deno-docker.
runs main.ts with --allow-net set and requires deps.ts for dependencies`,
FileText: `
FROM hayd/alpine-deno:1.2.1
EXPOSE 8080
Expand All @@ -84,7 +91,8 @@ var basicbuiltins = []Builtin{
CMD ["run", "--allow-net", "main.ts"]
`},
Builtin{Name: "go",
Description: "Builtin Go - Builds app.go uses go modules",
Description: "Go Builtin",
Details: `Builds app.go from the directory, the app should use go modules.`,
FileText: `
FROM golang:1.13 as builder
WORKDIR /go/src/app
Expand All @@ -99,7 +107,8 @@ var basicbuiltins = []Builtin{
CMD ["/app"]
`},
Builtin{Name: "static",
Description: "Builtin Static - Static web server. All files are copied across and served",
Description: "Web server builtin",
Details: `All files are copied to the image and served`,
FileText: `
FROM pierrezemb/gostatic
COPY . /srv/http/
Expand Down
49 changes: 49 additions & 0 deletions cmd/builtins.go
@@ -0,0 +1,49 @@
package cmd

import (
"os"
"sort"

"github.com/olekukonko/tablewriter"
"github.com/superfly/flyctl/builtinsupport"
"github.com/superfly/flyctl/cmdctx"

"github.com/superfly/flyctl/docstrings"

"github.com/spf13/cobra"
)

func newBuiltinsCommand() *Command {
builtinsStrings := docstrings.Get("builtins")

cmd := &Command{
Command: &cobra.Command{
Use: builtinsStrings.Usage,
Short: builtinsStrings.Short,
Long: builtinsStrings.Long,
},
}

builtinsListStrings := docstrings.Get("builtins.list")
BuildCommandKS(cmd, runListBuiltins, builtinsListStrings, os.Stdout)

return cmd
}

func runListBuiltins(commandContext *cmdctx.CmdContext) error {
builtins := builtinsupport.GetBuiltins()

sort.Slice(builtins, func(i, j int) bool { return builtins[i].Name < builtins[j].Name })

builtintable := tablewriter.NewWriter(commandContext.Out)
builtintable.SetHeader([]string{"Name", "Description", "Details"})

for _, builtin := range builtins {
builtintable.Append([]string{builtin.Name, builtin.Description, builtin.Details})
builtintable.Append([]string{"", "", ""})
}

builtintable.Render()

return nil
}
1 change: 1 addition & 0 deletions cmd/root.go
Expand Up @@ -93,6 +93,7 @@ func init() {
newVersionCommand(),
newDNSCommand(),
newOrgsCommand(),
newBuiltinsCommand(),
)

initConfig()
Expand Down
30 changes: 21 additions & 9 deletions helpgen/flyctlhelp.toml
Expand Up @@ -309,32 +309,32 @@ shortHelp="Manage DNS zones"
longHelp="Manage DNS zones"

[dns.zones.list]
usage="list <org>"
usage="list [<org>]"
shortHelp="List DNS zones"
longHelp="List DNS zones"
longHelp="List DNS zones for an organization"

[dns.zones.create]
usage="create <org> <domain>"
usage="create [<org> <domain>]"
shortHelp="Create a DNS zone"
longHelp="Create a DNS zone"
longHelp="Create a DNS zone for an organization"

[dns.zones.delete]
usage="delete <org> <domain>"
usage="delete [<org> <domain>]"
shortHelp="Delete a DNS zone"
longHelp="Delete a DNS zone"

[dns.records]
usage="records"
shortHelp="Manage DNS records"
longHelp="Manage DNS records"
longHelp="Manage DNS records within a zone"

[dns.records.list]
usage="list <org> <domain>"
usage="list [<org> <domain>]"
shortHelp="List DNS records"
longHelp="List DNS records"
longHelp="List DNS records within a zone"

[dns.records.export]
usage="export <org> <domain>"
usage="export [<org> <domain>]"
shortHelp="Export DNS records"
longHelp="Export DNS records"

Expand Down Expand Up @@ -603,3 +603,15 @@ longHelp="""Shows version information for the flyctl command itself,
including version number and build date.
"""

[builtins]
usage="builtins"
shortHelp="View and manage Flyctl deployment builtins"
longHelp="""View and manage Flyctl deployment builtins.
"""

[builtins.list]
usage="list"
shortHelp="List available Flyctl deployment builtins"
longHelp="""List available Flyctl deployment builtins and their
descriptions.
"""

0 comments on commit b88c1f1

Please sign in to comment.