Skip to content

Commit

Permalink
feat: add flag to force update hertz_client.go (#1165)
Browse files Browse the repository at this point in the history
  • Loading branch information
FGYFFFF authored Aug 1, 2024
1 parent 9536ec4 commit dbd3166
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions cmd/hz/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}

Expand Down Expand Up @@ -316,6 +317,7 @@ func Init() *cli.App {
&clientDirFlag,
&useFlag,
&forceClientDirFlag,
&forceUpdateClientFlag,

&includesFlag,
&thriftOptionsFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/hz/config/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ type Argument struct {
NoRecurse bool
HandlerByMethod bool
ForceNew bool
ForceUpdateClient bool
SnakeStyleMiddleware bool
EnableExtends bool
SortRouter bool
Expand Down
2 changes: 1 addition & 1 deletion cmd/hz/generator/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/hz/generator/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/hz/protobuf/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/hz/thrift/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit dbd3166

Please sign in to comment.