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
[Question] May I ask how the command line tool nests grouping? #2838
Comments
https://goframe.org/pages/viewpage.action?pageId=35357523, you can read this document description |
https://goframe.org/pages/viewpage.action?pageId=35357523 |
就是看了,没搞明白才提问呀 |
I just saw it, I didn't understand it, so I asked. |
我想的实现的是和 gf gen xxx 类似的风格,但是文档并没有给出这样的示例,看了 gf gen 源码,我自己模拟,似乎只能加一个,多个不行,参考:#2838 (comment) @gqcn |
What I want to achieve is a style similar to gf gen xxx, but the document does not give such an example. After reading the source code of gf gen, I simulated it myself. It seems that I can only add one, not multiple. Reference: https:// github.com//issues/2838#issue-1836357144 @gqcn |
@shuqingzai 嵌套形式本质上是同层的方法。Http Grpc AAA BBB Hello是同层的东西,只是人为用对象区分了一下,所以他们并不能重复。 package main
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gctx"
)
type cMain struct {
g.Meta `name:"main"`
CTest
cHello
}
type cMainHttpInput struct {
g.Meta `name:"http" brief:"start http server"`
}
type cMainHttpOutput struct{}
type cMainGrpcInput struct {
g.Meta `name:"grpc" brief:"start grpc server"`
}
type cMainGrpcOutput struct{}
func (c *cMain) Http(ctx context.Context, in cMainHttpInput) (out *cMainHttpOutput, err error) {
fmt.Println("start http server")
return
}
func (c *cMain) Grpc(ctx context.Context, in cMainGrpcInput) (out *cMainGrpcOutput, err error) {
fmt.Println("start grpc server")
return
}
type CTest struct {
}
type cTestInput struct {
g.Meta `name:"test" brief:"我是test命令"` // 主要看这个name
}
type cTestOutput struct{}
func (c CTest) AAA(ctx context.Context, in cTestInput) (out *cTestOutput, err error) { // 这里的方法名字千万不能和其它重复
fmt.Println("Test")
return
}
type cTomInput struct {
g.Meta `name:"tom" brief:"我是tom命令"` // 主要看这个name
}
type cTomOutput struct{}
func (c CTest) BBB(ctx context.Context, in cTomInput) (out *cTomOutput, err error) {
fmt.Println("Test")
return
}
type cHello struct {
}
type cHelloInput struct {
g.Meta `name:"hello" brief:"我是hello命令"` // 主要看这个name
}
type cHelloOutput struct{}
func (c *cHello) Hello(ctx context.Context, in cHelloInput) (out *cHelloOutput, err error) {
fmt.Println("Hello")
return
}
func main() {
cmd, err := gcmd.NewFromObject(cMain{}) // 这是单层
if err != nil {
panic(err)
}
// cmd.AddObject(cMain{}) // 这是多层,懒得写新的了,直接叠加main,就变成main main test
cmd.Run(gctx.New())
} |
@shuqingzai Nested forms are essentially methods at the same level. Http Grpc AAA BBB Hello is the same layer, but it is artificially distinguished by objects, so they cannot be repeated. package main
import (
"context"
"fmt"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcmd"
"github.com/gogf/gf/v2/os/gctx"
)
type cMain struct {
g.Meta `name: "main"`
CTest
Hello
}
type cMainHttpInput struct {
g.Meta `name:"http" brief:"start http server"`
}
type cMainHttpOutput struct{}
type cMainGrpcInput struct {
g.Meta `name:"grpc" brief:"start grpc server"`
}
type cMainGrpcOutput struct{}
func (c *cMain) Http(ctx context.Context, in cMainHttpInput) (out *cMainHttpOutput, err error) {
fmt.Println("start http server")
return
}
func (c *cMain) Grpc(ctx context.Context, in cMainGrpcInput) (out *cMainGrpcOutput, err error) {
fmt.Println("start grpc server")
return
}
type CTest struct {
}
type cTestInput struct {
g.Meta `name:"test" brief: "I am the test command"` // Mainly look at this name
}
type cTestOutput struct{}
func (c CTest) AAA(ctx context.Context, in cTestInput) (out *cTestOutput, err error) { // The method name here must not be the same as other
fmt.Println("Test")
return
}
type cTomInput struct {
g.Meta `name:"tom" brief: "I am the tom command"` // Mainly look at this name
}
type cTomOutput struct{}
func (c CTest) BBB(ctx context.Context, in cTomInput) (out *cTomOutput, err error) {
fmt.Println("Test")
return
}
type cHello struct {
}
type cHelloInput struct {
g.Meta `name:"hello" brief: "I am the hello command"` // Mainly look at this name
}
type cHelloOutput struct{}
func (c *cHello) Hello(ctx context.Context, in cHelloInput) (out *cHelloOutput, err error) {
fmt.Println("Hello")
return
}
func main() {
cmd, err := gcmd.NewFromObject(cMain{}) // this is a single layer
if err != nil {
panic(err)
}
// cmd.AddObject(cMain{}) // This is multi-layer, too lazy to write a new one, directly superimpose main, it becomes main main test
cmd.Run(gctx.New())
} |
|
我看到 gf 的是可以按以下方式分组
但是我这边尝试的时候,添加一个子命令可以分组的,多个就不行,多个的时候,子命令直接丢失
加两个直接没了子命令
1. What version of
Go
and system type/arch are you using?#-> % go version go version go1.20.6 darwin/amd64
2. What version of
GoFrame
are you using?3. Can this issue be re-produced with the latest release?
4. What did you do?
5. What did you expect to see?
6. What did you see instead?
The text was updated successfully, but these errors were encountered: