Skip to content

Commit

Permalink
feat: support new project
Browse files Browse the repository at this point in the history
  • Loading branch information
cjphaha committed Jan 27, 2022
1 parent 22daf7b commit a56ed31
Show file tree
Hide file tree
Showing 17 changed files with 877 additions and 20 deletions.
14 changes: 12 additions & 2 deletions cmd/dubbogo-cli-v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## How to use

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

```
```

### Create demo

```bash
./dubbogo-cli-v2 new --path=./demo
```

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.

![img.png](docs/demo/img.png)
12 changes: 11 additions & 1 deletion cmd/dubbogo-cli-v2/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,14 @@ methods: [CreateUser,GetUserByCode,GetUserByName,GetUserByNameAndAge,GetUserTime
interface: org.apache.dubbo.gate.basketballService
methods: []

```
```

### 创建 demo

```bash
./dubbogo-cli-v2 new --path=./demo
```

该命令会生成一个 dubbo-go 的样例,该样例可以参考 [HOWTO](https://github.com/apache/dubbo-go-samples/blob/master/HOWTO.md) 运行:

![img.png](docs/demo/img.png)
33 changes: 18 additions & 15 deletions cmd/dubbogo-cli-v2/cmd/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
package cmd

import (
"github.com/dubbogo/tools/internal/client"
"github.com/dubbogo/tools/internal/json_register"
"log"
)

import (
"github.com/spf13/cobra"
)

import (
"github.com/dubbogo/tools/internal/client"
"github.com/dubbogo/tools/internal/json_register"
)

// callCmd represents the call command
var (
callCmd = &cobra.Command{
Expand All @@ -50,22 +55,20 @@ var (

func init() {
rootCmd.AddCommand(callCmd)
showCmd.Flags().String("r", "localhost", "")
showCmd.Flags().Int("h", 8080, "")

showCmd.Flags().StringVarP(&host, "h", "", "localhost", "target server host")
showCmd.Flags().IntVarP(&port, "p", "", 8080, "target server port")
showCmd.Flags().StringVarP(&protocolName, "proto", "", "dubbo", "transfer protocol")
showCmd.Flags().StringVarP(&InterfaceID, "i", "", "com", "target service registered interface")
showCmd.Flags().StringVarP(&version, "v", "", "", "target service version")
showCmd.Flags().StringVarP(&group, "g", "", "", "target service group")
showCmd.Flags().StringVarP(&method, "method", "", "", "target method")
showCmd.Flags().StringVarP(&sendObjFilePath, "sendObj", "", "", "json file path to define transfer struct")
showCmd.Flags().StringVarP(&recvObjFilePath, "recvObj", "", "", "json file path to define receive struct")
showCmd.Flags().IntVarP(&timeout, "timeout", "", 3000, "request timeout (ms)")
callCmd.Flags().StringVarP(&host, "h", "", "localhost", "target server host")
callCmd.Flags().IntVarP(&port, "p", "", 8080, "target server port")
callCmd.Flags().StringVarP(&protocolName, "proto", "", "dubbo", "transfer protocol")
callCmd.Flags().StringVarP(&InterfaceID, "i", "", "com", "target service registered interface")
callCmd.Flags().StringVarP(&version, "v", "", "", "target service version")
callCmd.Flags().StringVarP(&group, "g", "", "", "target service group")
callCmd.Flags().StringVarP(&method, "method", "", "", "target method")
callCmd.Flags().StringVarP(&sendObjFilePath, "sendObj", "", "", "json file path to define transfer struct")
callCmd.Flags().StringVarP(&recvObjFilePath, "recvObj", "", "", "json file path to define receive struct")
callCmd.Flags().IntVarP(&timeout, "timeout", "", 3000, "request timeout (ms)")
}

func call(cmd *cobra.Command, args []string) {
func call(_ *cobra.Command, _ []string) {
checkParam()
reqPkg := json_register.RegisterStructFromFile(sendObjFilePath)
recvPkg := json_register.RegisterStructFromFile(recvObjFilePath)
Expand Down
48 changes: 48 additions & 0 deletions cmd/dubbogo-cli-v2/cmd/new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 cmd

import (
"github.com/spf13/cobra"
)

import (
"github.com/dubbogo/tools/cmd/dubbogo-cli-v2/generator/sample"
)

// newCmd represents the new command
var newCmd = &cobra.Command{
Use: "new",
Short: "new a dubbo-go demo project",
Run: createDemo,
}

func init() {
rootCmd.AddCommand(newCmd)
newCmd.Flags().String("path", "rootPath", "")
}

func createDemo(cmd *cobra.Command, _ []string) {
path, err := cmd.Flags().GetString("path")
if err != nil {
panic(err)
}
if err := sample.Generate(path); err != nil {
panic(err)
}
}
6 changes: 4 additions & 2 deletions cmd/dubbogo-cli-v2/cmd/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package cmd

import (
"fmt"
"github.com/dubbogo/tools/cmd/dubbogo-cli-v2/metadata"
"log"
)

import (
"github.com/spf13/cobra"
)

import (
"github.com/dubbogo/tools/cmd/dubbogo-cli-v2/metadata"
_ "github.com/dubbogo/tools/cmd/dubbogo-cli-v2/metadata/zookeeper"
)

Expand All @@ -43,7 +45,7 @@ func init() {
showCmd.Flags().String("h", "h", "")
}

func show(cmd *cobra.Command, args []string) {
func show(cmd *cobra.Command, _ []string) {
registry, err := cmd.Flags().GetString("r")
if err != nil {
panic(err)
Expand Down
Binary file added cmd/dubbogo-cli-v2/docs/demo/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit a56ed31

Please sign in to comment.