Skip to content

Commit a56ed31

Browse files
committed
feat: support new project
1 parent 22daf7b commit a56ed31

17 files changed

+877
-20
lines changed

cmd/dubbogo-cli-v2/README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
## How to use
66

7-
1. 安装
7+
1. Install
88
```bash
99
go get -u github.com/dubbogo/tools/cmd/dubbogo-cli-v2
1010
```
@@ -35,4 +35,14 @@ methods: [CreateUser,GetUserByCode,GetUserByName,GetUserByNameAndAge,GetUserTime
3535
interface: org.apache.dubbo.gate.basketballService
3636
methods: []
3737

38-
```
38+
```
39+
40+
### Create demo
41+
42+
```bash
43+
./dubbogo-cli-v2 new --path=./demo
44+
```
45+
46+
This command will generate a dubbo-go example, you can refer to the example [HOWTO](https://github.com/apache/dubbo-go-samples/blob/master/HOWTO.md) to run.
47+
48+
![img.png](docs/demo/img.png)

cmd/dubbogo-cli-v2/README_CN.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ methods: [CreateUser,GetUserByCode,GetUserByName,GetUserByNameAndAge,GetUserTime
3535
interface: org.apache.dubbo.gate.basketballService
3636
methods: []
3737

38-
```
38+
```
39+
40+
### 创建 demo
41+
42+
```bash
43+
./dubbogo-cli-v2 new --path=./demo
44+
```
45+
46+
该命令会生成一个 dubbo-go 的样例,该样例可以参考 [HOWTO](https://github.com/apache/dubbo-go-samples/blob/master/HOWTO.md) 运行:
47+
48+
![img.png](docs/demo/img.png)

cmd/dubbogo-cli-v2/cmd/call.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@
1818
package cmd
1919

2020
import (
21-
"github.com/dubbogo/tools/internal/client"
22-
"github.com/dubbogo/tools/internal/json_register"
2321
"log"
22+
)
2423

24+
import (
2525
"github.com/spf13/cobra"
2626
)
2727

28+
import (
29+
"github.com/dubbogo/tools/internal/client"
30+
"github.com/dubbogo/tools/internal/json_register"
31+
)
32+
2833
// callCmd represents the call command
2934
var (
3035
callCmd = &cobra.Command{
@@ -50,22 +55,20 @@ var (
5055

5156
func init() {
5257
rootCmd.AddCommand(callCmd)
53-
showCmd.Flags().String("r", "localhost", "")
54-
showCmd.Flags().Int("h", 8080, "")
5558

56-
showCmd.Flags().StringVarP(&host, "h", "", "localhost", "target server host")
57-
showCmd.Flags().IntVarP(&port, "p", "", 8080, "target server port")
58-
showCmd.Flags().StringVarP(&protocolName, "proto", "", "dubbo", "transfer protocol")
59-
showCmd.Flags().StringVarP(&InterfaceID, "i", "", "com", "target service registered interface")
60-
showCmd.Flags().StringVarP(&version, "v", "", "", "target service version")
61-
showCmd.Flags().StringVarP(&group, "g", "", "", "target service group")
62-
showCmd.Flags().StringVarP(&method, "method", "", "", "target method")
63-
showCmd.Flags().StringVarP(&sendObjFilePath, "sendObj", "", "", "json file path to define transfer struct")
64-
showCmd.Flags().StringVarP(&recvObjFilePath, "recvObj", "", "", "json file path to define receive struct")
65-
showCmd.Flags().IntVarP(&timeout, "timeout", "", 3000, "request timeout (ms)")
59+
callCmd.Flags().StringVarP(&host, "h", "", "localhost", "target server host")
60+
callCmd.Flags().IntVarP(&port, "p", "", 8080, "target server port")
61+
callCmd.Flags().StringVarP(&protocolName, "proto", "", "dubbo", "transfer protocol")
62+
callCmd.Flags().StringVarP(&InterfaceID, "i", "", "com", "target service registered interface")
63+
callCmd.Flags().StringVarP(&version, "v", "", "", "target service version")
64+
callCmd.Flags().StringVarP(&group, "g", "", "", "target service group")
65+
callCmd.Flags().StringVarP(&method, "method", "", "", "target method")
66+
callCmd.Flags().StringVarP(&sendObjFilePath, "sendObj", "", "", "json file path to define transfer struct")
67+
callCmd.Flags().StringVarP(&recvObjFilePath, "recvObj", "", "", "json file path to define receive struct")
68+
callCmd.Flags().IntVarP(&timeout, "timeout", "", 3000, "request timeout (ms)")
6669
}
6770

68-
func call(cmd *cobra.Command, args []string) {
71+
func call(_ *cobra.Command, _ []string) {
6972
checkParam()
7073
reqPkg := json_register.RegisterStructFromFile(sendObjFilePath)
7174
recvPkg := json_register.RegisterStructFromFile(recvObjFilePath)

cmd/dubbogo-cli-v2/cmd/new.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package cmd
19+
20+
import (
21+
"github.com/spf13/cobra"
22+
)
23+
24+
import (
25+
"github.com/dubbogo/tools/cmd/dubbogo-cli-v2/generator/sample"
26+
)
27+
28+
// newCmd represents the new command
29+
var newCmd = &cobra.Command{
30+
Use: "new",
31+
Short: "new a dubbo-go demo project",
32+
Run: createDemo,
33+
}
34+
35+
func init() {
36+
rootCmd.AddCommand(newCmd)
37+
newCmd.Flags().String("path", "rootPath", "")
38+
}
39+
40+
func createDemo(cmd *cobra.Command, _ []string) {
41+
path, err := cmd.Flags().GetString("path")
42+
if err != nil {
43+
panic(err)
44+
}
45+
if err := sample.Generate(path); err != nil {
46+
panic(err)
47+
}
48+
}

cmd/dubbogo-cli-v2/cmd/show.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ package cmd
1919

2020
import (
2121
"fmt"
22-
"github.com/dubbogo/tools/cmd/dubbogo-cli-v2/metadata"
2322
"log"
23+
)
2424

25+
import (
2526
"github.com/spf13/cobra"
2627
)
2728

2829
import (
30+
"github.com/dubbogo/tools/cmd/dubbogo-cli-v2/metadata"
2931
_ "github.com/dubbogo/tools/cmd/dubbogo-cli-v2/metadata/zookeeper"
3032
)
3133

@@ -43,7 +45,7 @@ func init() {
4345
showCmd.Flags().String("h", "h", "")
4446
}
4547

46-
func show(cmd *cobra.Command, args []string) {
48+
func show(cmd *cobra.Command, _ []string) {
4749
registry, err := cmd.Flags().GetString("r")
4850
if err != nil {
4951
panic(err)

cmd/dubbogo-cli-v2/docs/demo/img.png

6.62 KB
Loading

0 commit comments

Comments
 (0)