Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add flag to force update hertz_client.go #1165

Merged
merged 1 commit into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading