From db4e36369c3d5d62d5c66646c6bfcae7b3371661 Mon Sep 17 00:00:00 2001 From: fgy Date: Thu, 1 Aug 2024 14:12:43 +0800 Subject: [PATCH] feat: add flag to force update hertz_client.go --- cmd/hz/app/app.go | 2 ++ cmd/hz/config/argument.go | 1 + cmd/hz/generator/client.go | 2 +- cmd/hz/generator/package.go | 1 + cmd/hz/protobuf/plugin.go | 1 + cmd/hz/thrift/plugin.go | 1 + 6 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/hz/app/app.go b/cmd/hz/app/app.go index 739db8823..2885a7e56 100644 --- a/cmd/hz/app/app.go +++ b/cmd/hz/app/app.go @@ -178,6 +178,7 @@ func Init() *cli.App { protoPluginsFlag := cli.StringSliceFlag{Name: "protoc-plugins", Usage: "Specify plugins for the protoc. ({plugin_name}:{options}:{out_dir})"} noRecurseFlag := cli.BoolFlag{Name: "no_recurse", Usage: "Generate master model only.", Destination: &globalArgs.NoRecurse} forceNewFlag := cli.BoolFlag{Name: "force", Aliases: []string{"f"}, Usage: "Force new a project, which will overwrite the generated files", Destination: &globalArgs.ForceNew} + forceUpdateClientFlag := cli.BoolFlag{Name: "force_client", Usage: "Force update 'hertz_client.go'", Destination: &globalArgs.ForceUpdateClient} enableExtendsFlag := cli.BoolFlag{Name: "enable_extends", Usage: "Parse 'extends' for thrift IDL", Destination: &globalArgs.EnableExtends} sortRouterFlag := cli.BoolFlag{Name: "sort_router", Usage: "Sort router register code, to avoid code difference", Destination: &globalArgs.SortRouter} @@ -316,6 +317,7 @@ func Init() *cli.App { &clientDirFlag, &useFlag, &forceClientDirFlag, + &forceUpdateClientFlag, &includesFlag, &thriftOptionsFlag, diff --git a/cmd/hz/config/argument.go b/cmd/hz/config/argument.go index 48e381297..d9dcca441 100644 --- a/cmd/hz/config/argument.go +++ b/cmd/hz/config/argument.go @@ -71,6 +71,7 @@ type Argument struct { NoRecurse bool HandlerByMethod bool ForceNew bool + ForceUpdateClient bool SnakeStyleMiddleware bool EnableExtends bool SortRouter bool diff --git a/cmd/hz/generator/client.go b/cmd/hz/generator/client.go index 7545a5023..b1b887eaf 100644 --- a/cmd/hz/generator/client.go +++ b/cmd/hz/generator/client.go @@ -71,7 +71,7 @@ func (pkgGen *HttpPackageGenerator) genClient(pkg *HttpPackage, clientDir string BaseDomain: baseDomain, Config: ClientConfig{QueryEnumAsInt: pkgGen.QueryEnumAsInt}, } - if !isExist { + if !isExist || pkgGen.ForceUpdateClient { err := pkgGen.TemplateGenerator.Generate(client, hertzClientTplName, hertzClientPath, false) if err != nil { return err diff --git a/cmd/hz/generator/package.go b/cmd/hz/generator/package.go index db4d9762b..6896229b0 100644 --- a/cmd/hz/generator/package.go +++ b/cmd/hz/generator/package.go @@ -70,6 +70,7 @@ type HttpPackageGenerator struct { HandlerByMethod bool // generate handler files with method dimension SnakeStyleMiddleware bool // use snake name style for middleware SortRouter bool + ForceUpdateClient bool // force update 'hertz_client.go' loadedBackend Backend curModel *model.Model diff --git a/cmd/hz/protobuf/plugin.go b/cmd/hz/protobuf/plugin.go index fbae89929..abb7616c4 100644 --- a/cmd/hz/protobuf/plugin.go +++ b/cmd/hz/protobuf/plugin.go @@ -628,6 +628,7 @@ func (plugin *Plugin) genHttpPackage(ast *descriptorpb.FileDescriptorProto, deps QueryEnumAsInt: args.QueryEnumAsInt, SnakeStyleMiddleware: args.SnakeStyleMiddleware, SortRouter: args.SortRouter, + ForceUpdateClient: args.ForceUpdateClient, } if args.ModelBackend != "" { diff --git a/cmd/hz/thrift/plugin.go b/cmd/hz/thrift/plugin.go index 91fab02fc..0e773df30 100644 --- a/cmd/hz/thrift/plugin.go +++ b/cmd/hz/thrift/plugin.go @@ -153,6 +153,7 @@ func (plugin *Plugin) Run() int { QueryEnumAsInt: args.QueryEnumAsInt, SnakeStyleMiddleware: args.SnakeStyleMiddleware, SortRouter: args.SortRouter, + ForceUpdateClient: args.ForceUpdateClient, } if args.ModelBackend != "" { sg.Backend = meta.Backend(args.ModelBackend)