Skip to content

Commit

Permalink
feat(cli): add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
imiric committed Apr 18, 2024
1 parent d6f5111 commit 4ea2ba4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func New(dataDir string, opts ...Option) (*App, error) {
}
app.ctx.UUIDGen = uuidgen

app.cli, err = cli.New(dataDir)
app.cli, err = cli.New(dataDir, app.ctx.Version)
if err != nil {
return nil, err
}
Expand Down
12 changes: 8 additions & 4 deletions app/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ type CLI struct {
Invite Invite `kong:"cmd,help='Manage invitations for remote users.'"`
Remote Remote `kong:"cmd,help='Manage remote Disco nodes.'"`

DataDir string `kong:"default='${dataDir}',help='Directory to store Disco data in.'"`
EncryptionKey string `kong:"help='32-byte private key used for encrypting and decrypting the local data store, encoded in base 58. '"`
Version kong.VersionFlag `kong:"help='Output Disco version and exit.'"`
DataDir string `kong:"default='${dataDir}',help='Directory to store Disco data in.'"`
EncryptionKey string `kong:"help='32-byte private key used for encrypting and decrypting the local data store, encoded in base 58. '"`
Log struct {
Level slog.Level `enum:"DEBUG,INFO,WARN,ERROR" default:"INFO" help:"Set the app logging level."`
} `embed:"" prefix:"log-"`
}

// New initializes the command-line interface.
func New(dataDir string) (*CLI, error) {
func New(dataDir, version string) (*CLI, error) {
c := &CLI{}
kparser, err := kong.New(c,
kong.Name("disco"),
Expand All @@ -44,7 +45,10 @@ func New(dataDir string) (*CLI, error) {
Summary: true,
NoExpandSubcommands: true,
}),
kong.Vars{"dataDir": dataDir},
kong.Vars{
"dataDir": dataDir,
"version": version,
},
)
if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion app/version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package app

const version = "0.0.0"
// The app version is extracted from Git and set by the Go linker at build time.
var version string

0 comments on commit 4ea2ba4

Please sign in to comment.