Skip to content

Commit 25222ed

Browse files
committed
Merge branch 'develop' into refactor/kitex_tool
2 parents 1427831 + c8e8365 commit 25222ed

File tree

8 files changed

+79
-45
lines changed

8 files changed

+79
-45
lines changed

tool/cmd/kitex/args/args.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ type ExtraFlag struct {
5454
// Arguments .
5555
type Arguments struct {
5656
generator.Config
57-
extends []*ExtraFlag
58-
queryVersion bool
59-
dependencyChecker *versions.DependencyChecker
57+
extends []*ExtraFlag
58+
queryVersion bool
6059
}
6160

6261
const (
@@ -98,7 +97,6 @@ func (a *Arguments) buildFlags(version string) *flag.FlagSet {
9897
"Turn on verbose mode.")
9998
f.BoolVar(&a.GenerateInvoker, "invoker", false,
10099
"Generate invoker side codes when service name is specified.")
101-
f.StringVar(&a.IDLType, "type", "unknown", "Specify the type of IDL: 'thrift' or 'protobuf'.")
102100
f.Var(&a.Includes, "I", "Add an IDL search path for includes.")
103101
f.Var(&a.ThriftOptions, "thrift", "Specify arguments for the thrift go compiler.")
104102
f.Var(&a.Hessian2Options, "hessian2", "Specify arguments for the hessian2 codec.")
@@ -255,16 +253,11 @@ func (a *Arguments) checkIDL(files []string) error {
255253
}
256254
a.IDL = files[0]
257255

258-
switch a.IDLType {
259-
case Thrift, Protobuf:
260-
case Unknown:
261-
if typ, ok := guessIDLType(a.IDL); ok {
262-
a.IDLType = typ
263-
} else {
264-
return fmt.Errorf("can not guess an IDL type from %q (unknown suffix), please specify with the '-type' flag", a.IDL)
265-
}
266-
default:
267-
return fmt.Errorf("unsupported IDL type: %s", a.IDLType)
256+
if typ, ok := guessIDLType(a.IDL); ok {
257+
a.IDLType = typ
258+
} else {
259+
return fmt.Errorf("the last parameter shoule be IDL filename (xxx.thrift or xxx.proto), for example: " +
260+
"\"kitex -service demo idl.thrift\"")
268261
}
269262
return nil
270263
}

tool/cmd/kitex/utils/utils.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,13 @@
1515
package utils
1616

1717
import (
18-
"os/exec"
19-
"strings"
20-
2118
kargs "github.com/cloudwego/kitex/tool/cmd/kitex/args"
2219
"github.com/cloudwego/kitex/tool/internal_pkg/log"
2320
"github.com/cloudwego/kitex/tool/internal_pkg/pluginmode/thriftgo"
2421
)
2522

2623
func OnKitexToolNormalExit(args kargs.Arguments) {
2724
log.Info("Code Generation is Done!")
28-
29-
if args.IDLType == "thrift" {
30-
cmd := "go mod edit -replace github.com/apache/thrift=github.com/apache/thrift@v0.13.0"
31-
argv := strings.Split(cmd, " ")
32-
err := exec.Command(argv[0], argv[1:]...).Run()
33-
if err != nil {
34-
log.Warnf("Tips: please execute the following command to fix apache thrift lib version.\n%s", cmd)
35-
}
36-
}
37-
3825
// If hessian option is java_extension, replace *java.Object to java.Object
3926
if thriftgo.EnableJavaExtension(args.Config) {
4027
if err := thriftgo.Hessian2PatchByReplace(args.Config, ""); err != nil {

tool/cmd/kitex/versions/dependencies_v2.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func CheckVersion() (ok bool, err error) {
8585
if !currentVersion.greatOrEqual(minDepRepoVersion) {
8686
prompt := cr.promptFunc(cr.minDepRepoPath, currentVersionStr, kitex.Version)
8787
log.Infof(prompt)
88-
return false, fmt.Errorf("kitex cmd tool dependency compatibility check failed")
88+
return false, ErrDependencyVersionNotCompatible
8989
}
9090

9191
return true, nil

tool/internal_pkg/log/log.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
"fmt"
1919
"log"
2020
"os"
21+
22+
"github.com/cloudwego/kitex/tool/internal_pkg/util"
2123
)
2224

2325
// Verbose decides whether the informatc logs should be output.
@@ -48,24 +50,28 @@ func SetDefaultLogger(l Logger) {
4850
defaultLogger = l
4951
}
5052

53+
var errorPrefix = util.Bold + util.FgRed + "[ERROR] " + util.Reset
54+
55+
var warningPrefix = util.Bold + util.FgYellow + "[WARN] " + util.Reset
56+
5157
// Error ...
5258
func Error(v ...interface{}) {
53-
defaultLogger.Printf("[ERROR] %s", fmt.Sprintln(v...))
59+
defaultLogger.Printf("%s%s", errorPrefix, fmt.Sprintln(v...))
5460
}
5561

5662
// Errorf ...
5763
func Errorf(format string, v ...interface{}) {
58-
defaultLogger.Printf("[ERROR] "+format, v...)
64+
defaultLogger.Printf(errorPrefix+format, v...)
5965
}
6066

6167
// Warn ...
6268
func Warn(v ...interface{}) {
63-
defaultLogger.Printf("[WARN] %s", fmt.Sprintln(v...))
69+
defaultLogger.Printf("%s %s", warningPrefix, fmt.Sprintln(v...))
6470
}
6571

6672
// Warnf ...
6773
func Warnf(format string, v ...interface{}) {
68-
defaultLogger.Printf("[WARN] "+format, v...)
74+
defaultLogger.Printf(warningPrefix+format, v...)
6975
}
7076

7177
// Info ...

tool/internal_pkg/pluginmode/thriftgo/convertor.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ func (c *converter) init(req *plugin.Request) error {
6666
}
6767

6868
func (c *converter) initLogs() backend.LogFunc {
69+
// todo fix log
70+
// todo 单步验证 thriftgo log
6971
lf := backend.LogFunc{
7072
Info: func(v ...interface{}) {},
7173
Warn: func(v ...interface{}) {
@@ -75,13 +77,13 @@ func (c *converter) initLogs() backend.LogFunc {
7577
c.Warnings = append(c.Warnings, warns...)
7678
},
7779
}
78-
if c.Config.Verbose {
79-
lf.Info = lf.Warn
80-
}
80+
//if c.Config.Verbose {
81+
// lf.Info = lf.Warn
82+
//}
8183

82-
log.SetDefaultLogger(log.LoggerFunc(func(format string, a ...interface{}) {
83-
c.Warnings = append(c.Warnings, fmt.Sprintf(format, a...))
84-
}))
84+
//log.SetDefaultLogger(log.LoggerFunc(func(format string, a ...interface{}) {
85+
// c.Warnings = append(c.Warnings, fmt.Sprintf(format, a...))
86+
//}))
8587
return lf
8688
}
8789

tool/internal_pkg/pluginmode/thriftgo/plugin.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import (
1919
"fmt"
2020
"os"
2121

22+
"github.com/cloudwego/kitex/tool/internal_pkg/log"
23+
2224
"github.com/cloudwego/thriftgo/plugin"
2325

2426
"github.com/cloudwego/kitex/tool/internal_pkg/generator"
@@ -129,8 +131,7 @@ func HandleRequest(req *plugin.Request) *plugin.Response {
129131
if conv.Config.Use != "" {
130132
err := conv.persist(res)
131133
if err == nil {
132-
// todo 检测这里的效果?修改打印!
133-
fmt.Println("kitex_gen is not generated due to the -use option")
134+
log.Info("kitex_gen is not generated due to the -use option")
134135
return res
135136
}
136137
return conv.failResp(err)

tool/internal_pkg/thriftgo/thriftgo.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
kargs "github.com/cloudwego/kitex/tool/cmd/kitex/args"
2424
"github.com/cloudwego/kitex/tool/cmd/kitex/code"
25-
"github.com/cloudwego/kitex/tool/internal_pkg/log"
2625
"github.com/cloudwego/thriftgo/plugin"
2726
"github.com/cloudwego/thriftgo/sdk"
2827
)
@@ -64,10 +63,6 @@ func RunKitexThriftgoGenFromArgs(wd string, plugins []plugin.SDKPlugin, argsPars
6463

6564
plugins = append([]plugin.SDKPlugin{p}, plugins...)
6665

67-
// fixme
68-
l := log.DefaultLogger() // pluginmode/thriftgo/convertor.go will change the logger
69-
defer log.SetDefaultLogger(l) // revert it back
70-
7166
err = sdk.RunThriftgoAsSDK(wd, plugins, p.GetThriftgoParameters()...)
7267
if err == nil {
7368
return nil, code.ToolSuccess

tool/internal_pkg/util/color.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package util
2+
3+
// Define common ANSI escape code constants
4+
const (
5+
Reset = "\x1b[0m" // Reset all attributes
6+
// Regular Colors (Foreground)
7+
FgBlack = "\x1b[30m"
8+
FgRed = "\x1b[31m"
9+
FgGreen = "\x1b[32m"
10+
FgYellow = "\x1b[33m"
11+
FgBlue = "\x1b[34m"
12+
FgMagenta = "\x1b[35m"
13+
FgCyan = "\x1b[36m"
14+
FgWhite = "\x1b[37m"
15+
// Bright/High-Intensity Colors (Foreground)
16+
FgBrightBlack = "\x1b[90m" // Often called Gray
17+
FgBrightRed = "\x1b[91m"
18+
FgBrightGreen = "\x1b[92m"
19+
FgBrightYellow = "\x1b[93m"
20+
FgBrightBlue = "\x1b[94m"
21+
FgBrightMagenta = "\x1b[95m"
22+
FgBrightCyan = "\x1b[96m"
23+
FgBrightWhite = "\x1b[97m"
24+
// Background Colors
25+
BgBlack = "\x1b[40m"
26+
BgRed = "\x1b[41m"
27+
BgGreen = "\x1b[42m"
28+
BgYellow = "\x1b[43m"
29+
BgBlue = "\x1b[44m"
30+
BgMagenta = "\x1b[45m"
31+
BgCyan = "\x1b[46m"
32+
BgWhite = "\x1b[47m"
33+
// Bright/High-Intensity Background Colors
34+
BgBrightBlack = "\x1b[100m"
35+
BgBrightRed = "\x1b[101m"
36+
BgBrightGreen = "\x1b[102m"
37+
BgBrightYellow = "\x1b[103m"
38+
BgBrightBlue = "\x1b[104m"
39+
BgBrightMagenta = "\x1b[105m"
40+
BgBrightCyan = "\x1b[106m"
41+
BgBrightWhite = "\x1b[107m"
42+
// Styles
43+
Bold = "\x1b[1m"
44+
Dim = "\x1b[2m" // Dim/Faint
45+
Italic = "\x1b[3m" // Italic (not supported by all terminals)
46+
Underline = "\x1b[4m" // Underline
47+
Blink = "\x1b[5m" // Blink (not supported by all terminals)
48+
Reverse = "\x1b[7m" // Reverse foreground and background colors
49+
Hidden = "\x1b[8m" // Hidden (useful for password input)
50+
)

0 commit comments

Comments
 (0)