-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 新增 mode 参数,指定文件的写入方式:write 和 append - 根据 mode 参数,决定代码的生成位置(支持创建指定文件并写入和追加到指定文件)
- Loading branch information
1 parent
33a11e8
commit 44cee50
Showing
11 changed files
with
554 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Generated by [optioner] command-line tool; DO NOT EDIT | ||
// If you have any questions, please create issues and submit contributions at: | ||
// https://github.com/chenmingyong0423/go-optioner | ||
|
||
// Copyright 2024 chenmingyong0423 | ||
|
||
// 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 example | ||
|
||
import "context" | ||
|
||
type _ struct { | ||
_ context.Context | ||
} | ||
|
||
type GenericExampleOption[T any, U comparable, V ~int] func(*GenericExample[T, U, V]) | ||
|
||
func NewGenericExample[T any, U comparable, V ~int](a T, opts ...GenericExampleOption[T, U, V]) *GenericExample[T, U, V] { | ||
genericExample := &GenericExample[T, U, V]{ | ||
A: a, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(genericExample) | ||
} | ||
|
||
return genericExample | ||
} | ||
|
||
func WithB[T any, U comparable, V ~int](b U) GenericExampleOption[T, U, V] { | ||
return func(genericExample *GenericExample[T, U, V]) { | ||
genericExample.B = b | ||
} | ||
} | ||
|
||
func WithC[T any, U comparable, V ~int](c V) GenericExampleOption[T, U, V] { | ||
return func(genericExample *GenericExample[T, U, V]) { | ||
genericExample.C = c | ||
} | ||
} | ||
|
||
func WithD[T any, U comparable, V ~int](d string) GenericExampleOption[T, U, V] { | ||
return func(genericExample *GenericExample[T, U, V]) { | ||
genericExample.D = d | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// Generated by [optioner] command-line tool; DO NOT EDIT | ||
// If you have any questions, please create issues and submit contributions at: | ||
// https://github.com/chenmingyong0423/go-optioner | ||
|
||
// Copyright 2024 chenmingyong0423 | ||
|
||
// 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 example | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/chenmingyong0423/go-optioner/example/third_party" | ||
) | ||
|
||
type _ struct { | ||
_ context.Context | ||
} | ||
|
||
type UserOption func(*User) | ||
|
||
func NewUser(embedded Embedded, embedded2 *Embedded2, e3 Embedded3, e4 *Embedded4, opts ...UserOption) *User { | ||
user := &User{ | ||
Embedded: embedded, | ||
Embedded2: embedded2, | ||
E3: e3, | ||
E4: e4, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(user) | ||
} | ||
|
||
return user | ||
} | ||
|
||
func WithEmbedded5(embedded5 Embedded5) UserOption { | ||
return func(user *User) { | ||
user.Embedded5 = embedded5 | ||
} | ||
} | ||
|
||
func WithEmbedded6(embedded6 *Embedded6) UserOption { | ||
return func(user *User) { | ||
user.Embedded6 = embedded6 | ||
} | ||
} | ||
|
||
func WithE7(e7 Embedded7) UserOption { | ||
return func(user *User) { | ||
user.E7 = e7 | ||
} | ||
} | ||
|
||
func WithE8(e8 *Embedded8) UserOption { | ||
return func(user *User) { | ||
user.E8 = e8 | ||
} | ||
} | ||
|
||
func WithUsername(username string) UserOption { | ||
return func(user *User) { | ||
user.Username = username | ||
} | ||
} | ||
|
||
func WithEmail(email string) UserOption { | ||
return func(user *User) { | ||
user.Email = email | ||
} | ||
} | ||
|
||
func WithAddress(address Address) UserOption { | ||
return func(user *User) { | ||
user.Address = address | ||
} | ||
} | ||
|
||
func WithArrayField(arrayField [4]int) UserOption { | ||
return func(user *User) { | ||
user.ArrayField = arrayField | ||
} | ||
} | ||
|
||
func WithSliceField(sliceField []int) UserOption { | ||
return func(user *User) { | ||
user.SliceField = sliceField | ||
} | ||
} | ||
|
||
func WithThirdPartyField(thirdPartyField third_party.ThirdParty) UserOption { | ||
return func(user *User) { | ||
user.ThirdPartyField = thirdPartyField | ||
} | ||
} | ||
|
||
func WithMapField(mapField map[string]int) UserOption { | ||
return func(user *User) { | ||
user.MapField = mapField | ||
} | ||
} | ||
|
||
func WithPtrField(ptrField *int) UserOption { | ||
return func(user *User) { | ||
user.PtrField = ptrField | ||
} | ||
} | ||
|
||
func WithEmptyStructFiled(emptyStructFiled struct{}) UserOption { | ||
return func(user *User) { | ||
user.EmptyStructFiled = emptyStructFiled | ||
} | ||
} | ||
|
||
func WithSimpleFuncField(simpleFuncField func()) UserOption { | ||
return func(user *User) { | ||
user.SimpleFuncField = simpleFuncField | ||
} | ||
} | ||
|
||
func WithComplexFuncField(complexFuncField func(a int)) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncField = complexFuncField | ||
} | ||
} | ||
|
||
func WithComplexFuncFieldV2(complexFuncFieldV2 func() int) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncFieldV2 = complexFuncFieldV2 | ||
} | ||
} | ||
|
||
func WithComplexFuncFieldV3(complexFuncFieldV3 func(a int) int) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncFieldV3 = complexFuncFieldV3 | ||
} | ||
} | ||
|
||
func WithComplexFuncFieldV4(complexFuncFieldV4 func(a int) (int, error)) UserOption { | ||
return func(user *User) { | ||
user.ComplexFuncFieldV4 = complexFuncFieldV4 | ||
} | ||
} | ||
|
||
func WithChanField(chanField chan int) UserOption { | ||
return func(user *User) { | ||
user.ChanField = chanField | ||
} | ||
} | ||
|
||
func WithError(error error) UserOption { | ||
return func(user *User) { | ||
user.error = error | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Generated by [optioner] command-line tool; DO NOT EDIT | ||
// If you have any questions, please create issues and submit contributions at: | ||
// https://github.com/chenmingyong0423/go-optioner | ||
|
||
package example | ||
|
||
type GenericExampleOption[T any, U comparable, V ~int] func(*GenericExample[T, U, V]) | ||
|
||
func NewGenericExample[T any, U comparable, V ~int](a T, opts ...GenericExampleOption[T, U, V]) *GenericExample[T, U, V] { | ||
genericExample := &GenericExample[T, U, V]{ | ||
A: a, | ||
} | ||
|
||
for _, opt := range opts { | ||
opt(genericExample) | ||
} | ||
|
||
return genericExample | ||
} | ||
|
||
func WithB[T any, U comparable, V ~int](b U) GenericExampleOption[T, U, V] { | ||
return func(genericExample *GenericExample[T, U, V]) { | ||
genericExample.B = b | ||
} | ||
} | ||
|
||
func WithC[T any, U comparable, V ~int](c V) GenericExampleOption[T, U, V] { | ||
return func(genericExample *GenericExample[T, U, V]) { | ||
genericExample.C = c | ||
} | ||
} | ||
|
||
func WithD[T any, U comparable, V ~int](d string) GenericExampleOption[T, U, V] { | ||
return func(genericExample *GenericExample[T, U, V]) { | ||
genericExample.D = d | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.