@@ -16,22 +16,26 @@ import (
1616 "github.com/input-output-hk/catalyst-forge/lib/project/schema"
1717 "github.com/input-output-hk/catalyst-forge/lib/project/secrets"
1818 "github.com/input-output-hk/catalyst-forge/lib/tools/walker"
19+ "github.com/posener/complete"
20+ "github.com/willabides/kongplete"
1921)
2022
2123var version = "dev"
2224
2325var cli struct {
2426 cmds.GlobalArgs
2527
26- Deploy cmds.DeployCmd `cmd:"" help:"Deploy a project."`
27- Dump cmds.DumpCmd `cmd:"" help:"Dumps a project's blueprint to JSON."`
28- CI cmds.CICmd `cmd:"" help:"Simulate a CI run."`
29- Run cmds.RunCmd `cmd:"" help:"Run an Earthly target."`
30- Scan cmds.ScanCmd `cmd:"" help:"Scan for Earthfiles."`
31- Secret cmds.SecretCmd `cmd:"" help:"Manage secrets."`
32- Tag cmds.TagCmd `cmd:"" help:"Generate a tag for a project."`
33- Validate cmds.ValidateCmd `cmd:"" help:"Validates a project."`
34- Version VersionCmd `cmd:"" help:"Print the version."`
28+ Deploy cmds.DeployCmd `kong:"cmd" help:"Deploy a project." `
29+ Dump cmds.DumpCmd `kong:"cmd" help:"Dumps a project's blueprint to JSON."`
30+ CI cmds.CICmd `kong:"cmd" help:"Simulate a CI run."`
31+ Run cmds.RunCmd `kong:"cmd" help:"Run an Earthly target."`
32+ Scan cmds.ScanCmd `kong:"cmd" help:"Scan for Earthfiles."`
33+ Secret cmds.SecretCmd `kong:"cmd" help:"Manage secrets."`
34+ Tag cmds.TagCmd `kong:"cmd" help:"Generate a tag for a project."`
35+ Validate cmds.ValidateCmd `kong:"cmd" help:"Validates a project."`
36+ Version VersionCmd `kong:"cmd" help:"Print the version."`
37+
38+ InstallCompletions kongplete.InstallCompletions `cmd:"" help:"install shell completions"`
3539}
3640
3741type VersionCmd struct {}
@@ -50,10 +54,16 @@ func (c *VersionCmd) Run() error {
5054
5155// Run is the entrypoint for the CLI tool.
5256func Run () int {
53- ctx := kong .Parse (& cli ,
57+ cliArgs := os .Args [1 :]
58+
59+ parser := kong .Must (& cli ,
5460 kong .Name ("forge" ),
5561 kong .Description ("The CLI tool powering Catalyst Forge" ))
5662
63+ kongplete .Complete (parser ,
64+ kongplete .WithPredictor ("path" , complete .PredictFiles ("*" )),
65+ )
66+
5767 handler := log .New (os .Stderr )
5868 switch cli .Verbose {
5969 case 0 :
@@ -66,6 +76,12 @@ func Run() int {
6676 handler .SetLevel (log .DebugLevel )
6777 }
6878
79+ ctx , err := parser .Parse (cliArgs )
80+ if err != nil {
81+ fmt .Fprintf (os .Stderr , "forge: %v\n " , err )
82+ return 1
83+ }
84+
6985 logger := slog .New (handler )
7086 loader := project .NewDefaultProjectLoader (logger )
7187 runctx := run.RunContext {
@@ -83,9 +99,8 @@ func Run() int {
8399 }
84100 ctx .Bind (runctx )
85101
86- err := ctx .Run ()
87- if err != nil {
88- fmt .Fprintf (os .Stderr , "forge: %v" , err )
102+ if err := ctx .Run (); err != nil {
103+ fmt .Fprintf (os .Stderr , "forge: %v\n " , err )
89104 return 1
90105 }
91106
0 commit comments