@@ -13,10 +13,15 @@ import (
1313 "github.com/coder/serpent"
1414)
1515
16+ // printVersion prints version information.
17+ func printVersion (version string ) {
18+ fmt .Println (version )
19+ }
20+
1621// NewCommand creates and returns the root serpent command
17- func NewCommand () * serpent.Command {
22+ func NewCommand (version string ) * serpent.Command {
1823 // To make the top level boundary command, we just make some minor changes to the base command
19- cmd := BaseCommand ()
24+ cmd := BaseCommand (version )
2025 cmd .Use = "boundary [flags] -- command [args...]" // Add the flags and args pieces to usage.
2126
2227 // Add example usage to the long description. This is different from usage as a subcommand because it
@@ -39,8 +44,9 @@ func NewCommand() *serpent.Command {
3944// Base command returns the boundary serpent command without the information involved in making it the
4045// *top level* serpent command. We are creating this split to make it easier to integrate into the coder
4146// CLI if needed.
42- func BaseCommand () * serpent.Command {
47+ func BaseCommand (version string ) * serpent.Command {
4348 cliConfig := config.CliConfig {}
49+ var showVersion serpent.Bool
4450
4551 // Set default config path if file exists - serpent will load it automatically
4652 if home , err := os .UserHomeDir (); err == nil {
@@ -149,8 +155,19 @@ func BaseCommand() *serpent.Command {
149155 Value : & cliConfig .LogProxySocketPath ,
150156 YAML : "" , // CLI only, not loaded from YAML
151157 },
158+ {
159+ Flag : "version" ,
160+ Description : "Print version information and exit." ,
161+ Value : & showVersion ,
162+ YAML : "" , // CLI only
163+ },
152164 },
153165 Handler : func (inv * serpent.Invocation ) error {
166+ // Handle --version flag early
167+ if showVersion .Value () {
168+ printVersion (version )
169+ return nil
170+ }
154171 appConfig , err := config .NewAppConfigFromCliConfig (cliConfig , inv .Args )
155172 if err != nil {
156173 return fmt .Errorf ("failed to parse cli config file: %v" , err )
0 commit comments