diff --git a/frontend/cli/main.go b/frontend/cli/main.go index 6db7e1814..98beec383 100644 --- a/frontend/cli/main.go +++ b/frontend/cli/main.go @@ -12,6 +12,7 @@ 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" @@ -32,27 +33,28 @@ type CLI struct { Insecure bool `help:"Skip TLS certificate verification. Caution: susceptible to machine-in-the-middle attacks."` Plain bool `help:"Use a plain console with no color or status line." env:"FTL_PLAIN"` - 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 and the secret will be stored in the password field." placeholder:"VAULT"` @@ -62,7 +64,8 @@ var cli CLI func main() { ctx, cancel := context.WithCancel(context.Background()) - kctx := kong.Parse(&cli, + + app := kong.Must(&cli, kong.Description(`FTL - Towards a 𝝺-calculus for large-scale systems`), kong.Configuration(kongtoml.Loader, ".ftl.toml", "~/.ftl.toml"), kong.ShortUsageOnError(), @@ -81,6 +84,11 @@ func main() { "numcpu": strconv.Itoa(runtime.NumCPU()), }, ) + kongcompletion.Register(app) + kctx, err := app.Parse(os.Args[1:]) + if err != nil { + panic(err) + } if !cli.Plain { sm := status.NewStatusManager(ctx) diff --git a/go.mod b/go.mod index 1dbdc9d37..40e2ee6fc 100644 --- a/go.mod +++ b/go.mod @@ -37,6 +37,7 @@ require ( github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438 github.com/jackc/pgx/v5 v5.7.1 github.com/jellydator/ttlcache/v3 v3.3.0 + github.com/jotaen/kong-completion v0.0.6 github.com/jpillora/backoff v1.0.0 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/mattn/go-isatty v0.0.20 @@ -103,6 +104,8 @@ 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 @@ -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 diff --git a/go.sum b/go.sum index 14a0e3160..6f13421ca 100644 --- a/go.sum +++ b/go.sum @@ -176,6 +176,12 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 h1:asbCHRVmodnJTuQ3qamDwqVOIjw github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0/go.mod h1:ggCgvZ2r7uOoQjOyu2Y1NhHmEPPzzuhWgcza5M1Ji1I= github.com/hashicorp/cronexpr v1.1.2 h1:wG/ZYIKT+RT3QkOdgYc+xsKWVRgnxJ1OJtjjy84fJ9A= github.com/hashicorp/cronexpr v1.1.2/go.mod h1:P4wA0KBl9C5q2hABiMO7cp6jcIg96CDh1Efb3g1PWA4= +github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= +github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= +github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= +github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= @@ -204,6 +210,8 @@ github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGw github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/jotaen/kong-completion v0.0.6 h1:VP1KGvXPeB7MytYR+zZQoWw1gf/HIV1/EvWC38BHZN4= +github.com/jotaen/kong-completion v0.0.6/go.mod h1:fuWw9snL6joY5mXbI0Dd5FWEZODaWXAeqaRxo6dAvLk= github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= @@ -275,6 +283,8 @@ github.com/pkoukk/tiktoken-go v0.1.6/go.mod h1:9NiV+i9mJKGj1rYOT+njbv+ZwA/zJxYde github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/puzpuzpuz/xsync/v3 v3.4.0 h1:DuVBAdXuGFHv8adVXjWWZ63pJq+NRXOWVXlKDBZ+mJ4= @@ -285,6 +295,8 @@ github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94 github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab h1:ZjX6I48eZSFetPb41dHudEyVr5v953N15TsNZXlkcWY= +github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab/go.mod h1:/PfPXh0EntGc3QAAyUaviy4S9tzy4Zp0e2ilq4voC6E= github.com/robertkrimen/otto v0.2.1 h1:FVP0PJ0AHIjC+N4pKCG9yCDz6LHNPCwi/GKID5pGGF0= github.com/robertkrimen/otto v0.2.1/go.mod h1:UPwtJ1Xu7JrLcZjNWN8orJaM5n5YEtqL//farB5FlRY= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= @@ -313,6 +325,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= @@ -441,6 +454,7 @@ gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc= gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw= gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI= gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=