From f955314b3d554e1d818650b905875e4c08429846 Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sat, 13 Jan 2024 21:15:43 -0500 Subject: Add version command --- internal/commands/version.go | 42 ++++++++++++++++++++++++++++++++++++++++++ pkg/cli/cli.go | 1 + 2 files changed, 43 insertions(+) create mode 100644 internal/commands/version.go diff --git a/internal/commands/version.go b/internal/commands/version.go new file mode 100644 index 0000000..d8cf338 --- /dev/null +++ b/internal/commands/version.go @@ -0,0 +1,42 @@ +package commands + +import ( + "context" + "flag" + + "github.com/eugenetriguba/bolt/internal/output" + "github.com/google/subcommands" +) + +type VersionCmd struct{} + +func (*VersionCmd) Name() string { + return "version" +} + +func (*VersionCmd) Synopsis() string { + return "show the current version of bolt" +} + +func (*VersionCmd) Usage() string { + return `version: + Show the current version of Bolt + ` +} + +func (cmd *VersionCmd) SetFlags(f *flag.FlagSet) {} + +func (cmd *VersionCmd) Execute( + _ context.Context, + f *flag.FlagSet, + _ ...interface{}, +) subcommands.ExitStatus { + consoleOutputter := output.NewConsoleOutputter() + err := consoleOutputter.Output("bolt v0.1.0") + if err != nil { + consoleOutputter.Error(err.Error()) + return subcommands.ExitFailure + } + + return subcommands.ExitSuccess +} diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index fb9d1f3..29a10ff 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -13,6 +13,7 @@ func Run() int { subcommands.Register(subcommands.HelpCommand(), "") subcommands.Register(subcommands.FlagsCommand(), "") subcommands.Register(subcommands.CommandsCommand(), "") + subcommands.Register(&commands.VersionCmd{}, "") subcommands.Register(&commands.NewCmd{}, "") subcommands.Register(&commands.UpCmd{}, "") subcommands.Register(&commands.DownCmd{}, "") -- cgit v1.2.3