From 3268d78936100a4cc930441a62547dbf70dba225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Barroso?= Date: Fri, 20 Dec 2024 13:15:16 +0100 Subject: [PATCH] feat: add conduit version (#2035) * feat: add conduit version * move version into its own pkg --- cmd/conduit/root/root.go | 8 +++--- cmd/conduit/root/root_test.go | 2 +- cmd/conduit/root/version/version.go | 44 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 5 deletions(-) create mode 100644 cmd/conduit/root/version/version.go diff --git a/cmd/conduit/root/root.go b/cmd/conduit/root/root.go index 008525205..653023604 100644 --- a/cmd/conduit/root/root.go +++ b/cmd/conduit/root/root.go @@ -21,6 +21,7 @@ import ( "path/filepath" "github.com/conduitio/conduit/cmd/conduit/root/pipelines" + "github.com/conduitio/conduit/cmd/conduit/root/version" "github.com/conduitio/conduit/pkg/conduit" "github.com/conduitio/conduit/pkg/foundation/cerrors" "github.com/conduitio/ecdysis" @@ -35,7 +36,7 @@ var ( ) type RootFlags struct { - Version bool `long:"version" short:"v" usage:"show current Conduit version" persistent:"true"` + Version bool `long:"version" short:"v" usage:"show the current Conduit version"` conduit.Config } @@ -113,10 +114,9 @@ func (c *RootCommand) Docs() ecdysis.Docs { func (c *RootCommand) SubCommands() []ecdysis.Command { return []ecdysis.Command{ - &ConfigCommand{ - rootCmd: c, - }, + &ConfigCommand{rootCmd: c}, &InitCommand{cfg: &c.cfg}, + &version.VersionCommand{}, &pipelines.PipelinesCommand{}, } } diff --git a/cmd/conduit/root/root_test.go b/cmd/conduit/root/root_test.go index d0d2f2170..fb475ec3f 100644 --- a/cmd/conduit/root/root_test.go +++ b/cmd/conduit/root/root_test.go @@ -32,7 +32,7 @@ func TestRootCommandFlags(t *testing.T) { persistent bool }{ {longName: "config.path", usage: "global conduit configuration file"}, - {longName: "version", shortName: "v", usage: "show current Conduit version", persistent: true}, + {longName: "version", shortName: "v", usage: "show the current Conduit version"}, {longName: "db.type", usage: "database type; accepts badger,postgres,inmemory,sqlite"}, {longName: "db.badger.path", usage: "path to badger DB"}, {longName: "db.postgres.connection-string", usage: "postgres connection string, may be a database URL or in PostgreSQL keyword/value format"}, diff --git a/cmd/conduit/root/version/version.go b/cmd/conduit/root/version/version.go new file mode 100644 index 000000000..669113146 --- /dev/null +++ b/cmd/conduit/root/version/version.go @@ -0,0 +1,44 @@ +// Copyright © 2024 Meroxa, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package version + +import ( + "context" + "fmt" + "os" + + "github.com/conduitio/conduit/pkg/conduit" + "github.com/conduitio/ecdysis" +) + +var ( + _ ecdysis.CommandWithExecute = (*VersionCommand)(nil) + _ ecdysis.CommandWithDocs = (*VersionCommand)(nil) +) + +type VersionCommand struct{} + +func (c *VersionCommand) Usage() string { return "version" } + +func (c *VersionCommand) Execute(_ context.Context) error { + _, _ = fmt.Fprintf(os.Stdout, "%s\n", conduit.Version(true)) + return nil +} + +func (c *VersionCommand) Docs() ecdysis.Docs { + return ecdysis.Docs{ + Short: "Show the current version of Conduit.", + } +}