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

feat(cli): bash autocomplete affecting on global flags #76

Merged
merged 37 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
88f00ca
feat: initial command registration
apskhem Oct 3, 2024
f0bff4f
feat: extractor function
apskhem Oct 3, 2024
bd7ffe3
feat: complete parsing
apskhem Oct 3, 2024
4dd7024
feat: id formatter
apskhem Oct 3, 2024
4a9e746
feat: process cmd
apskhem Oct 4, 2024
7319379
feat: executable
apskhem Oct 4, 2024
983dd76
Merge branch 'master' into feat/initial-devx
apskhem Oct 4, 2024
1ea1931
feat: stream output
apskhem Oct 4, 2024
2f2b52a
chore: msg
apskhem Oct 4, 2024
add3272
Merge branch 'master' into feat/initial-devx
apskhem Oct 7, 2024
65cf45b
chore: sync main
apskhem Oct 7, 2024
118c7e0
feat: check available command
apskhem Oct 7, 2024
8448731
chore: move test devx to testdata
apskhem Oct 7, 2024
9999874
refactor: move utils
apskhem Oct 8, 2024
73e5ea5
refactor: restructure
apskhem Oct 8, 2024
2b3322c
chore: remove comments
apskhem Oct 8, 2024
75f0b52
refactor: using executor
apskhem Oct 8, 2024
d9d9b2b
refactor: command executor matching
apskhem Oct 8, 2024
8de6e57
test: for devx
apskhem Oct 8, 2024
e88faa3
Merge pull request #63 from input-output-hk/feat/initial-devx
apskhem Oct 9, 2024
d4dc550
feat: install kongplete
apskhem Oct 14, 2024
6929997
feat: root completion installation
apskhem Oct 15, 2024
7c85c74
refactor: main.go
apskhem Oct 15, 2024
3bd8e95
feat: kong for cmds
apskhem Oct 15, 2024
2b98a4d
chore: remove unused command
apskhem Oct 15, 2024
f17e20b
Merge branch 'master' into feat/devx-autocomplete
apskhem Oct 15, 2024
447413d
revert: Earthfile
apskhem Oct 15, 2024
5dff33c
chore: fmt
apskhem Oct 15, 2024
21a4f97
feat: path completions to other commands
apskhem Oct 15, 2024
e89daf7
chore: remove devx
apskhem Oct 15, 2024
2cf7a24
chore: remove devx test
apskhem Oct 15, 2024
dc3b83c
revert: add earthfile
apskhem Oct 15, 2024
6510eac
fix: execution ordering
apskhem Oct 17, 2024
d826568
Merge branch 'master' into feat/devx-autocomplete
apskhem Oct 18, 2024
0588ca8
fix: main
apskhem Oct 18, 2024
3fda2c6
chore: go mod
apskhem Oct 18, 2024
3160482
Merge branch 'master' into feat/devx-autocomplete
stevenj Oct 21, 2024
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: 1 addition & 1 deletion cli/cmd/cmds/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type CICmd struct {
Artifact string `short:"a" help:"Dump all produced artifacts to the given path."`
Path string `arg:"" default:"" help:"The path to scan from."`
Path string `kong:"arg,predictor=path" default:"" help:"The path to scan from."`
Platform []string `short:"p" help:"Run the target with the given platform."`
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/cmds/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type DeployCmd struct {
Project string `arg:"" help:"The path to the project to deploy."`
Project string `arg:"" help:"The path to the project to deploy." kong:"arg,predictor=path"`
}

func (c *DeployCmd) Run(ctx run.RunContext) error {
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/cmds/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

type DumpCmd struct {
Project string `arg:"" help:"Path to the project."`
Project string `arg:"" help:"Path to the project." kong:"arg,predictor=path"`
Pretty bool `help:"Pretty print JSON output."`
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/cmds/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

type RunCmd struct {
Artifact string `short:"a" help:"Dump all produced artifacts to the given path."`
Path string `arg:"" help:"The path to the target to execute (i.e., ./dir1+test)."`
Path string `kong:"arg,predictor=path" help:"The path to the target to execute (i.e., ./dir1+test)."`
Platform []string `short:"p" help:"Run the target with the given platform."`
Pretty bool `help:"Pretty print JSON output."`
TargetArgs []string `arg:"" help:"Arguments to pass to the target." default:""`
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/cmds/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ScanCmd struct {
Earthfile bool `help:"Return the Earthfile targets for each project."`
Filter []string `short:"f" help:"Filter Earthfile targets by regular expression or blueprint results by path."`
Pretty bool `help:"Pretty print JSON output."`
RootPath string `arg:"" help:"Root path to scan for Earthfiles and their respective targets."`
RootPath string `kong:"arg,predictor=path" help:"Root path to scan for Earthfiles and their respective targets."`
}

func (c *ScanCmd) Run(ctx run.RunContext) error {
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/cmds/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ type Get struct {
Key string `short:"k" help:"The key inside of the secret to get."`
Project string `help:"Path to a project to use for getting secret configuration."`
Provider string `short:"p" help:"The provider of the secret store." default:"aws"`
Path string `arg:"" help:"The path to the secret (or path in a project blueprint if --project is specified)."`
Path string `kong:"arg,predictor=path" help:"The path to the secret (or path in a project blueprint if --project is specified)."`
}

type Set struct {
Field []string `short:"f" help:"A secret field to set."`
Provider string `short:"p" help:"The provider of the secret store." default:"aws"`
Path string `arg:"" help:"The path to the secret (or path in a project blueprint if --project is specified)."`
Path string `kong:"arg,predictor=path" help:"The path to the secret (or path in a project blueprint if --project is specified)."`
Project string `help:"Path to a project to use for getting secret configuration."`
Value string `arg:"" help:"The value to set." default:""`
}
Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/cmds/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

type TagCmd struct {
Pretty bool `short:"p" help:"Pretty print JSON output."`
Project string `arg:"" help:"The project to generate tags for."`
Project string `kong:"arg,predictor=path" help:"The project to generate tags for."`
Trim bool `short:"t" help:"Trim the project path from the git tag."`
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/cmds/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

type ValidateCmd struct {
Project string `arg:"" help:"Path to the project."`
Project string `kong:"arg,predictor=path" help:"Path to the project."`
}

func (c *ValidateCmd) Run(ctx run.RunContext) error {
Expand Down
43 changes: 29 additions & 14 deletions cli/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,27 @@ import (
"github.com/input-output-hk/catalyst-forge/lib/project/schema"
"github.com/input-output-hk/catalyst-forge/lib/project/secrets"
"github.com/input-output-hk/catalyst-forge/lib/tools/walker"
"github.com/posener/complete"
"github.com/willabides/kongplete"
)

var version = "dev"

var cli struct {
cmds.GlobalArgs

Deploy cmds.DeployCmd `cmd:"" help:"Deploy a project."`
Dump cmds.DumpCmd `cmd:"" help:"Dumps a project's blueprint to JSON."`
CI cmds.CICmd `cmd:"" help:"Simulate a CI run."`
Release cmds.ReleaseCmd `cmd:"" help:"Release a project."`
Run cmds.RunCmd `cmd:"" help:"Run an Earthly target."`
Scan cmds.ScanCmd `cmd:"" help:"Scan for Earthfiles."`
Secret cmds.SecretCmd `cmd:"" help:"Manage secrets."`
Tag cmds.TagCmd `cmd:"" help:"Generate a tag for a project."`
Validate cmds.ValidateCmd `cmd:"" help:"Validates a project."`
Version VersionCmd `cmd:"" help:"Print the version."`
Deploy cmds.DeployCmd `kong:"cmd" help:"Deploy a project."`
Dump cmds.DumpCmd `kong:"cmd" help:"Dumps a project's blueprint to JSON."`
CI cmds.CICmd `kong:"cmd" help:"Simulate a CI run."`
Release cmds.ReleaseCmd `kong:"cmd" help:"Release a project."`
Run cmds.RunCmd `kong:"cmd" help:"Run an Earthly target."`
Scan cmds.ScanCmd `kong:"cmd" help:"Scan for Earthfiles."`
Secret cmds.SecretCmd `kong:"cmd" help:"Manage secrets."`
Tag cmds.TagCmd `kong:"cmd" help:"Generate a tag for a project."`
Validate cmds.ValidateCmd `kong:"cmd" help:"Validates a project."`
Version VersionCmd `kong:"cmd" help:"Print the version."`

InstallCompletions kongplete.InstallCompletions `cmd:"" help:"install shell completions"`
}

type VersionCmd struct{}
Expand All @@ -50,10 +54,22 @@ func (c *VersionCmd) Run() error {

// Run is the entrypoint for the CLI tool.
func Run() int {
ctx := kong.Parse(&cli,
cliArgs := os.Args[1:]

parser := kong.Must(&cli,
kong.Name("forge"),
kong.Description("The CLI tool powering Catalyst Forge"))

kongplete.Complete(parser,
kongplete.WithPredictor("path", complete.PredictFiles("*")),
)

ctx, err := parser.Parse(cliArgs)
if err != nil {
fmt.Fprintf(os.Stderr, "forge: %v\n", err)
return 1
}

handler := log.New(os.Stderr)
switch cli.Verbose {
case 0:
Expand All @@ -79,9 +95,8 @@ func Run() int {
}
ctx.Bind(runctx)

err := ctx.Run()
if err != nil {
fmt.Fprintf(os.Stderr, "forge: %v", err)
if err := ctx.Run(); err != nil {
fmt.Fprintf(os.Stderr, "forge: %v\n", err)
return 1
}

Expand Down
5 changes: 5 additions & 0 deletions cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ require (
github.com/input-output-hk/catalyst-forge/lib/project v0.0.0
github.com/input-output-hk/catalyst-forge/lib/tools v0.0.0
github.com/migueleliasweb/go-github-mock v1.0.1
github.com/posener/complete v1.2.3
github.com/rogpeppe/go-internal v1.12.1-0.20240709150035-ccf4b4329d21
github.com/spf13/afero v1.11.0
github.com/stretchr/testify v1.9.0
github.com/willabides/kongplete v0.4.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
)

Expand Down Expand Up @@ -59,6 +61,8 @@ require (
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand All @@ -72,6 +76,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/riywo/loginshell v0.0.0-20200815045211-7d26008be1ab // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
Expand Down
12 changes: 12 additions & 0 deletions cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
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/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
Expand Down Expand Up @@ -173,11 +179,15 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/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/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0 h1:sadMIsgmHpEOGbUs6VtHBXRR1OHevnj7hLx9ZcdNGW4=
github.com/protocolbuffers/txtpbfmt v0.0.0-20230328191034-3462fbc510c0/go.mod h1:jgxiZysxFPM+iWKwQwPR+y+Jvo54ARd4EisXxKYpB5c=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
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/rogpeppe/go-internal v1.12.1-0.20240709150035-ccf4b4329d21 h1:igWZJluD8KtEtAgRyF4x6lqcxDry1ULztksMJh2mnQE=
github.com/rogpeppe/go-internal v1.12.1-0.20240709150035-ccf4b4329d21/go.mod h1:RMRJLmBOqWacUkmJHRMiPKh1S1m3PA7Zh4W80/kWPpg=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
Expand All @@ -193,6 +203,8 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/willabides/kongplete v0.4.0 h1:eivXxkp5ud5+4+NVN9e4goxC5mSh3n1RHov+gsblM2g=
github.com/willabides/kongplete v0.4.0/go.mod h1:0P0jtWD9aTsqPSUAl4de35DLghrr57XcayPyvqSi2X8=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down