Skip to content

Commit

Permalink
feat: bash completion
Browse files Browse the repository at this point in the history
fixes: #2707
  • Loading branch information
stuartwdouglas committed Sep 19, 2024
1 parent 4546243 commit 9b01084
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 24 deletions.
56 changes: 32 additions & 24 deletions frontend/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/alecthomas/kong"
kongtoml "github.com/alecthomas/kong-toml"

kongcompletion "github.com/jotaen/kong-completion"

"github.com/TBD54566975/ftl"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
_ "github.com/TBD54566975/ftl/internal/automaxprocs" // Set GOMAXPROCS to match Linux container CPU quota.
Expand All @@ -30,27 +32,28 @@ type CLI struct {
Authenticators map[string]string `help:"Authenticators to use for FTL endpoints." mapsep:"," env:"FTL_AUTHENTICATORS" placeholder:"HOST=EXE,…"`
Insecure bool `help:"Skip TLS certificate verification. Caution: susceptible to machine-in-the-middle attacks."`

Interactive interactiveCmd `cmd:"" help:"Interactive mode." default:""`
Ping pingCmd `cmd:"" help:"Ping the FTL cluster."`
Status statusCmd `cmd:"" help:"Show FTL status."`
Init initCmd `cmd:"" help:"Initialize a new FTL project."`
New newCmd `cmd:"" help:"Create a new FTL module."`
Dev devCmd `cmd:"" help:"Develop FTL modules. Will start the FTL cluster, build and deploy all modules found in the specified directories, and watch for changes."`
PS psCmd `cmd:"" help:"List deployments."`
Serve serveCmd `cmd:"" help:"Start the FTL server."`
Call callCmd `cmd:"" help:"Call an FTL function."`
Update updateCmd `cmd:"" help:"Update a deployment."`
Kill killCmd `cmd:"" help:"Kill a deployment."`
Schema schemaCmd `cmd:"" help:"FTL schema commands."`
Build buildCmd `cmd:"" help:"Build all modules found in the specified directories."`
Box boxCmd `cmd:"" help:"Build a self-contained Docker container for running a set of module."`
BoxRun boxRunCmd `cmd:"" hidden:"" help:"Run FTL inside an ftl-in-a-box container"`
Deploy deployCmd `cmd:"" help:"Build and deploy all modules found in the specified directories."`
Migrate migrateCmd `cmd:"" help:"Run a database migration, if required, based on the migration table."`
Download downloadCmd `cmd:"" help:"Download a deployment."`
Secret secretCmd `cmd:"" help:"Manage secrets."`
Config configCmd `cmd:"" help:"Manage configuration."`
Pubsub pubsubCmd `cmd:"" help:"Manage pub/sub."`
Interactive interactiveCmd `cmd:"" help:"Interactive mode." default:""`
Ping pingCmd `cmd:"" help:"Ping the FTL cluster."`
Status statusCmd `cmd:"" help:"Show FTL status."`
Init initCmd `cmd:"" help:"Initialize a new FTL project."`
New newCmd `cmd:"" help:"Create a new FTL module."`
Dev devCmd `cmd:"" help:"Develop FTL modules. Will start the FTL cluster, build and deploy all modules found in the specified directories, and watch for changes."`
PS psCmd `cmd:"" help:"List deployments."`
Serve serveCmd `cmd:"" help:"Start the FTL server."`
Call callCmd `cmd:"" help:"Call an FTL function."`
Update updateCmd `cmd:"" help:"Update a deployment."`
Kill killCmd `cmd:"" help:"Kill a deployment."`
Schema schemaCmd `cmd:"" help:"FTL schema commands."`
Build buildCmd `cmd:"" help:"Build all modules found in the specified directories."`
Box boxCmd `cmd:"" help:"Build a self-contained Docker container for running a set of module."`
BoxRun boxRunCmd `cmd:"" hidden:"" help:"Run FTL inside an ftl-in-a-box container"`
Deploy deployCmd `cmd:"" help:"Build and deploy all modules found in the specified directories."`
Migrate migrateCmd `cmd:"" help:"Run a database migration, if required, based on the migration table."`
Download downloadCmd `cmd:"" help:"Download a deployment."`
Secret secretCmd `cmd:"" help:"Manage secrets."`
Config configCmd `cmd:"" help:"Manage configuration."`
Pubsub pubsubCmd `cmd:"" help:"Manage pub/sub."`
Completion kongcompletion.Completion `cmd:"" help:"Outputs shell code for initialising tab completions"`

// Specify the 1Password vault to access secrets from.
Vault string `name:"opvault" help:"1Password vault to be used for secrets. The name of the 1Password item will be the <ref> and the secret will be stored in the password field." placeholder:"VAULT"`
Expand All @@ -59,7 +62,9 @@ type CLI struct {
var cli CLI

func main() {
kctx := kong.Parse(&cli,
ctx, cancel := context.WithCancel(context.Background())

app := kong.Must(&cli,
kong.Description(`FTL - Towards a 𝝺-calculus for large-scale systems`),
kong.Configuration(kongtoml.Loader, ".ftl.toml", "~/.ftl.toml"),
kong.ShortUsageOnError(),
Expand All @@ -78,14 +83,17 @@ func main() {
"numcpu": strconv.Itoa(runtime.NumCPU()),
},
)
kongcompletion.Register(app)
kctx, err := app.Parse(os.Args[1:])
if err != nil {
panic(err)
}

rpc.InitialiseClients(cli.Authenticators, cli.Insecure)

// Set some envars for child processes.
os.Setenv("LOG_LEVEL", cli.LogConfig.Level.String())

ctx, cancel := context.WithCancel(context.Background())

logger := log.Configure(os.Stderr, cli.LogConfig)
ctx = log.ContextWithLogger(ctx, logger)

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,14 @@ require (
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/jotaen/kong-completion v0.0.6 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -124,7 +127,9 @@ require (
github.com/petermattis/goid v0.0.0-20240813172612-4fcff4a6cae7 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkoukk/tiktoken-go v0.1.6 // indirect
github.com/posener/complete v1.2.3 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab // indirect
github.com/sasha-s/go-deadlock v0.3.5 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/sourcegraph/jsonrpc2 v0.2.0 // indirect
Expand Down
14 changes: 14 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9b01084

Please sign in to comment.