From 70d684393c8387576bd289440646db095286995c Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Fri, 7 Jun 2024 14:39:50 +0800 Subject: [PATCH 1/8] feat:add kitexcall version --- pkg/argparse/args.go | 9 +++++++++ pkg/argparse/args_test.go | 8 ++++++++ pkg/config/config.go | 6 ++++++ 3 files changed, 23 insertions(+) diff --git a/pkg/argparse/args.go b/pkg/argparse/args.go index 08b8ed2..0a81a74 100644 --- a/pkg/argparse/args.go +++ b/pkg/argparse/args.go @@ -103,6 +103,8 @@ func (a *Argument) buildFlags() *flag.FlagSet { f.BoolVar(&a.MetaBackward, "meta-backward", false, "Enable receiving backward metainfo from server.") + f.BoolVar(&a.Version, "version", false, "Show the version of kitexcall.") + return f } @@ -116,6 +118,7 @@ func (a *Argument) PreJudge(f *flag.FlagSet) { Usage(f) os.Exit(0) } + } func (a *Argument) ParseArgs() error { @@ -126,6 +129,11 @@ func (a *Argument) ParseArgs() error { a.PreJudge(f) + if a.Version { + fmt.Printf("kitexcall version %s\n", config.Version) + os.Exit(0) + } + log.Verbose = a.Verbose log.Info("Parse args succeed") @@ -270,6 +278,7 @@ func (a *Argument) BuildConfig() *config.Config { MetaPersistent: a.MetaPersistent, MetaBackward: a.MetaBackward, BizError: a.BizError, + Version: a.Version, } } diff --git a/pkg/argparse/args_test.go b/pkg/argparse/args_test.go index d1b5a4e..f9a9ba2 100644 --- a/pkg/argparse/args_test.go +++ b/pkg/argparse/args_test.go @@ -53,6 +53,14 @@ func TestAugment_ParseArgs(t *testing.T) { wantErr: true, wantErrMsg: "IDL path is required", }, + { + name: "Test with version", + args: []string{ + "-version", + }, + wantErr: false, + wantErrMsg: "", + }, } { t.Run(tt.name, func(t *testing.T) { // Simulate command-line arguments diff --git a/pkg/config/config.go b/pkg/config/config.go index 12fb042..1ff9640 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -30,6 +30,11 @@ const ( TTHeaderFramed string = "TTHeaderFramed" ) +//kitexcall version +const ( + Version string = "0.1.1" +) + // We provide a general configuration // so that it can be utilized by others apart from kitexcall. type Config struct { @@ -46,6 +51,7 @@ type Config struct { MetaPersistent map[string]string MetaBackward bool BizError bool + Version bool } type ConfigBuilder interface { From 97f6f77c1867e7054345a42d17fa0488b2332250 Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Fri, 7 Jun 2024 14:56:24 +0800 Subject: [PATCH 2/8] feat:add kitexcall version --- pkg/argparse/args.go | 1 - 1 file changed, 1 deletion(-) diff --git a/pkg/argparse/args.go b/pkg/argparse/args.go index 0a81a74..4110b91 100644 --- a/pkg/argparse/args.go +++ b/pkg/argparse/args.go @@ -118,7 +118,6 @@ func (a *Argument) PreJudge(f *flag.FlagSet) { Usage(f) os.Exit(0) } - } func (a *Argument) ParseArgs() error { From 9b66a805b4a93934e3954fac8dfda1839a514fb8 Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Fri, 7 Jun 2024 15:00:16 +0800 Subject: [PATCH 3/8] feat: add kitexcall version --- pkg/argparse/args_test.go | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pkg/argparse/args_test.go b/pkg/argparse/args_test.go index f9a9ba2..d1b5a4e 100644 --- a/pkg/argparse/args_test.go +++ b/pkg/argparse/args_test.go @@ -53,14 +53,6 @@ func TestAugment_ParseArgs(t *testing.T) { wantErr: true, wantErrMsg: "IDL path is required", }, - { - name: "Test with version", - args: []string{ - "-version", - }, - wantErr: false, - wantErrMsg: "", - }, } { t.Run(tt.name, func(t *testing.T) { // Simulate command-line arguments From bca63c247bb8380e26d944a16fc42edb48f6bc1a Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Fri, 7 Jun 2024 17:27:11 +0800 Subject: [PATCH 4/8] Change where the version number is stored --- pkg/argparse/args.go | 7 ++++--- pkg/config/config.go | 5 ----- pkg/versions/version.go | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 pkg/versions/version.go diff --git a/pkg/argparse/args.go b/pkg/argparse/args.go index 4110b91..9e8bfd8 100644 --- a/pkg/argparse/args.go +++ b/pkg/argparse/args.go @@ -25,6 +25,7 @@ import ( "github.com/kitex-contrib/kitexcall/pkg/config" "github.com/kitex-contrib/kitexcall/pkg/errors" "github.com/kitex-contrib/kitexcall/pkg/log" + "github.com/kitex-contrib/kitexcall/pkg/versions" ) type Argument struct { @@ -129,8 +130,8 @@ func (a *Argument) ParseArgs() error { a.PreJudge(f) if a.Version { - fmt.Printf("kitexcall version %s\n", config.Version) - os.Exit(0) + fmt.Printf("kitexcall version %s\n", versions.Version) + os.Exit(0) } log.Verbose = a.Verbose @@ -277,7 +278,7 @@ func (a *Argument) BuildConfig() *config.Config { MetaPersistent: a.MetaPersistent, MetaBackward: a.MetaBackward, BizError: a.BizError, - Version: a.Version, + Version: a.Version, } } diff --git a/pkg/config/config.go b/pkg/config/config.go index 1ff9640..f9cad4a 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -30,11 +30,6 @@ const ( TTHeaderFramed string = "TTHeaderFramed" ) -//kitexcall version -const ( - Version string = "0.1.1" -) - // We provide a general configuration // so that it can be utilized by others apart from kitexcall. type Config struct { diff --git a/pkg/versions/version.go b/pkg/versions/version.go new file mode 100644 index 0000000..5f9e361 --- /dev/null +++ b/pkg/versions/version.go @@ -0,0 +1,23 @@ +/* + * Copyright 2021 CloudWeGo Authors + * + * 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 versions + +// Name and Version info of this framework, used for statistics and debug +const ( + Name = "Kitexcall" + Version = "v0.1.1" +) \ No newline at end of file From 63168a5dbb387d15aa51256d6618c990468ff1f6 Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Fri, 7 Jun 2024 17:39:19 +0800 Subject: [PATCH 5/8] format --- pkg/versions/version.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/versions/version.go b/pkg/versions/version.go index 5f9e361..fd059a6 100644 --- a/pkg/versions/version.go +++ b/pkg/versions/version.go @@ -14,10 +14,10 @@ * limitations under the License. */ - package versions +package versions // Name and Version info of this framework, used for statistics and debug const ( Name = "Kitexcall" Version = "v0.1.1" -) \ No newline at end of file +) From 0cab2ae27b733d223afb0c6fdbbd93b7795e46c7 Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Fri, 7 Jun 2024 18:04:00 +0800 Subject: [PATCH 6/8] add kitex version --- pkg/versions/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/versions/version.go b/pkg/versions/version.go index fd059a6..5d3f88c 100644 --- a/pkg/versions/version.go +++ b/pkg/versions/version.go @@ -1,5 +1,5 @@ /* - * Copyright 2021 CloudWeGo Authors + * Copyright 2024 CloudWeGo Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From a8016443227a8a28d2acfd8a9c480f7368f5a3be Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Sat, 8 Jun 2024 18:33:55 +0800 Subject: [PATCH 7/8] modify --- pkg/argparse/args.go | 6 ++---- pkg/config/config.go | 1 - pkg/versions/version.go | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pkg/argparse/args.go b/pkg/argparse/args.go index 9e8bfd8..4edc8c9 100644 --- a/pkg/argparse/args.go +++ b/pkg/argparse/args.go @@ -31,6 +31,7 @@ import ( type Argument struct { config.Config help bool + version bool } func NewArgument() *Argument { @@ -104,8 +105,6 @@ func (a *Argument) buildFlags() *flag.FlagSet { f.BoolVar(&a.MetaBackward, "meta-backward", false, "Enable receiving backward metainfo from server.") - f.BoolVar(&a.Version, "version", false, "Show the version of kitexcall.") - return f } @@ -129,7 +128,7 @@ func (a *Argument) ParseArgs() error { a.PreJudge(f) - if a.Version { + if a.version { fmt.Printf("kitexcall version %s\n", versions.Version) os.Exit(0) } @@ -278,7 +277,6 @@ func (a *Argument) BuildConfig() *config.Config { MetaPersistent: a.MetaPersistent, MetaBackward: a.MetaBackward, BizError: a.BizError, - Version: a.Version, } } diff --git a/pkg/config/config.go b/pkg/config/config.go index f9cad4a..12fb042 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -46,7 +46,6 @@ type Config struct { MetaPersistent map[string]string MetaBackward bool BizError bool - Version bool } type ConfigBuilder interface { diff --git a/pkg/versions/version.go b/pkg/versions/version.go index 5d3f88c..8e08d2e 100644 --- a/pkg/versions/version.go +++ b/pkg/versions/version.go @@ -18,6 +18,6 @@ package versions // Name and Version info of this framework, used for statistics and debug const ( - Name = "Kitexcall" + Name = "kitexcall" Version = "v0.1.1" ) From 6c5217010aa912b8a91a5331ca73e10abb0ca388 Mon Sep 17 00:00:00 2001 From: SHENCaesar Date: Tue, 11 Jun 2024 13:18:09 +0800 Subject: [PATCH 8/8] modify --- pkg/argparse/args.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pkg/argparse/args.go b/pkg/argparse/args.go index 4edc8c9..7ee2144 100644 --- a/pkg/argparse/args.go +++ b/pkg/argparse/args.go @@ -30,7 +30,7 @@ import ( type Argument struct { config.Config - help bool + help bool version bool } @@ -105,6 +105,8 @@ func (a *Argument) buildFlags() *flag.FlagSet { f.BoolVar(&a.MetaBackward, "meta-backward", false, "Enable receiving backward metainfo from server.") + f.BoolVar(&a.version, "version", false, "Show the version of kitexcall.") + return f } @@ -129,7 +131,7 @@ func (a *Argument) ParseArgs() error { a.PreJudge(f) if a.version { - fmt.Printf("kitexcall version %s\n", versions.Version) + fmt.Fprintln(os.Stderr, versions.Version) os.Exit(0) }