You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ch...@apache.org on 2019/12/23 06:00:10 UTC
[servicecomb-toolkit] 01/04: [SCB-1663] add scripts
This is an automated email from the ASF dual-hosted git repository.
chanjarster pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-toolkit.git
commit 11de7d9b4069d1523e88f4c3b33195cf781e68b0
Author: kakulisen <18...@163.com>
AuthorDate: Thu Dec 12 22:39:36 2019 +0800
[SCB-1663] add scripts
Signed-off-by: kakulisen <18...@163.com>
---
README-ZH.md | 17 ++++----
README.md | 17 ++++----
cli/scripts/cli.cmd | 67 +++++++++++++++++++++++++++++++
cli/scripts/cli.sh | 37 +++++++++++++++++
toolkit-distribution/src/assembly/bin.xml | 8 ++++
5 files changed, 130 insertions(+), 16 deletions(-)
diff --git a/README-ZH.md b/README-ZH.md
index 8fc4c2c..1dcd770 100644
--- a/README-ZH.md
+++ b/README-ZH.md
@@ -234,13 +234,14 @@ mvn toolkit:verify
### 3.3 使用toolkit cli工具
-可执行jar包位于toolkit/cli/target/bin目录下
+* 如果你使用的是正式发布版本(>=0.2.0),可以在解压二进制包后直接使用cli.sh
+* 如果你是通过源码构建,可以将`cli/scripts/cli.sh`与`cli/target/bin/toolkit-cli-{version}.jar`放置在同一目录,然后使用cli.sh
```shell
-$ java -jar toolkit-cli-{version}.jar help
+$ ./cli.sh help
```
#### 3.3.1 契约生成微服务工程
```shell
-$ java -jar toolkit-cli-{version}.jar codegenerate -m ServiceComb -i swagger.yaml -o ./project -p SpringMVC
+$ ./cli.sh codegenerate -m ServiceComb -i swagger.yaml -o ./project -p SpringMVC
```
> **codegenerate** 命令选项说明:
* -m, --microservice-framework : 指定微服务框架,现支持ServiceComb
@@ -266,7 +267,7 @@ $ java -jar toolkit-cli-{version}.jar codegenerate -m ServiceComb -i swagger.ya
#### 3.3.2 契约生成文档
```shell
-$ java -jar toolkit-cli-{version}.jar docgenerate -i swagger.yaml -o ./document
+$ ./cli.sh docgenerate -i swagger.yaml -o ./document
```
> **docgenerate** 命令选项说明:
* -i, --input : 指定遵循OpenAPI规范的契约文件,支持yaml和json格式,支持指定本地和网络文件
@@ -279,9 +280,9 @@ $ java -jar toolkit-cli-{version}.jar docgenerate -i swagger.yaml -o ./document
#### 3.3.3 契约风格检查
```shell
-$ java -jar toolkit-cli-{version}.jar checkstyle -r style-check-rules.yaml -f oas.yaml
+$ ./cli.sh checkstyle -r style-check-rules.yaml -f oas.yaml
or
-$ java -jar toolkit-cli-{version}.jar cs -r style-check-rules.yaml -f oas.yaml
+$ ./cli.sh cs -r style-check-rules.yaml -f oas.yaml
```
> **checkstyle** Command argument
@@ -293,9 +294,9 @@ $ java -jar toolkit-cli-{version}.jar cs -r style-check-rules.yaml -f oas.yaml
#### 3.3.4 契约兼容性检查
```shell
-$ java -jar toolkit-cli-{version}.jar checkcompatibility left-oas.yaml right-oas.yaml
+$ ./cli.sh checkcompatibility left-oas.yaml right-oas.yaml
或者
-$ java -jar toolkit-cli-{version}.jar cc left-oas.yaml right-oas.yaml
+$ ./cli.sh cc left-oas.yaml right-oas.yaml
```
> **checkcompatibility** Command argument
diff --git a/README.md b/README.md
index 6ee5217..55123d7 100644
--- a/README.md
+++ b/README.md
@@ -229,13 +229,14 @@ mvn toolkit:verify
### 3.3 Use the toolkit cli
-The executable jar package is located in the toolkit/cli/target/bin directory
+* If you are using the official release version ( >=0.2.0 ), you can use cli.sh directly after decompressing the binary package
+* If you are building from source, you can put `cli/scripts/cli.sh` in the same directory as`cli/target/bin/toolkit-cli-{version}.jar` and then use cli.sh
```shell
-$ java -jar toolkit-cli-{version}.jar help
+$ ./cli.sh help
```
#### 3.3.1 Service contract generation microservice project
```shell
-$ java -jar toolkit-cli-{version}.jar codegenerate -m ServiceComb -i swagger.yaml -o ./project -p SpringMVC
+$ ./cli.sh codegenerate -m ServiceComb -i swagger.yaml -o ./project -p SpringMVC
```
> **codegenerate** Command option
* -m, --microservice-framework. Specify microservices framework, now supports ServiceComb.
@@ -261,7 +262,7 @@ e.g.:--service-type provider
#### 3.3.2 Service contract generation document
```shell
-$ java -jar toolkit-cli-{version}.jar docgenerate -i swagger.yaml -o ./document
+$ ./cli.sh docgenerate -i swagger.yaml -o ./document
```
> **docgenerate** Command option
* -i, --input. Specifies contract files that follow the OpenAPI specification, supports yaml and json formats, and supports specifying local and network files.
@@ -274,9 +275,9 @@ e.g:-f swagger-ui
#### 3.3.3 Service contract style checking
```shell
-$ java -jar toolkit-cli-{version}.jar checkstyle -r style-check-rules.yaml -f oas.yaml
+$ ./cli.sh checkstyle -r style-check-rules.yaml -f oas.yaml
or
-$ java -jar toolkit-cli-{version}.jar cs -r style-check-rules.yaml -f oas.yaml
+$ ./cli.sh cs -r style-check-rules.yaml -f oas.yaml
```
> **checkstyle** Command argument
@@ -288,9 +289,9 @@ See [style check rules](oas-validator/README.md)
#### 3.3.4 Service contract compatibility checking
```shell
-$ java -jar toolkit-cli-{version}.jar checkcompatibility left-oas.yaml right-oas.yaml
+$ ./cli.sh checkcompatibility left-oas.yaml right-oas.yaml
or
-$ java -jar toolkit-cli-{version}.jar cc left-oas.yaml right-oas.yaml
+$ ./cli.sh cc left-oas.yaml right-oas.yaml
```
> **checkcompatibility** Command argument
diff --git a/cli/scripts/cli.cmd b/cli/scripts/cli.cmd
new file mode 100644
index 0000000..0e07d35
--- /dev/null
+++ b/cli/scripts/cli.cmd
@@ -0,0 +1,67 @@
+@REM Licensed to the Apache Software Foundation (ASF) under one or more
+@REM contributor license agreements. See the NOTICE file distributed with
+@REM this work for additional information regarding copyright ownership.
+@REM The ASF licenses this file to You under the Apache License, Version 2.0
+@REM (the "License"); you may not use this file except in compliance with
+@REM the License. You may obtain a copy of the License at
+@REM
+@REM http://www.apache.org/licenses/LICENSE-2.0
+@REM
+@REM Unless required by applicable law or agreed to in writing, software
+@REM distributed under the License is distributed on an "AS IS" BASIS,
+@REM WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@REM See the License for the specific language governing permissions and
+@REM limitations under the License.
+
+@echo off && rem
+
+set SUCCESS_CODE=0
+set ERROR_CODE=1
+
+@REM check if java install
+if "%JAVA_HOME%" == "" goto JAVA_HOME_ERROR
+if not exist "%JAVA_HOME%\bin\java.exe" goto JAVA_HOME_ERROR
+
+set jarFile=
+for /f "delims=" %%t in ('dir /S /B cli-*.jar') do set jarFile=%%t
+
+@REM check if jar file exist
+if "%jarFile%" == "" (
+ echo Error: cli.jar not exist. make sure it is placed in the current directory or subdirectory of this script
+ exit /B %ERROR_CODE%
+)
+
+set allparam=
+:param
+set str=%1
+if "%str%"=="" (
+ goto end
+)
+set allparam=%allparam% %str%
+shift /0
+goto param
+
+:end
+if "%allparam%"=="" (
+ goto eof
+)
+
+rem remove left right blank
+:intercept_left
+if "%allparam:~0,1%"==" " set "allparam=%allparam:~1%"&goto intercept_left
+
+:intercept_right
+if "%allparam:~-1%"==" " set "allparam=%allparam:~0,-1%"&goto intercept_right
+
+:eof
+
+java -jar %jarFile% %allparam%
+exit /B %SUCCESS_CODE%
+
+:JAVA_HOME_ERROR
+echo.
+echo Error: JAVA_HOME invalid in your environment. >&2
+echo Please set the JAVA_HOME variable in your environment to match the >&2
+echo location of your Java installation. >&2
+echo.
+exit /B %ERROR_CODE%
diff --git a/cli/scripts/cli.sh b/cli/scripts/cli.sh
new file mode 100755
index 0000000..9360bba
--- /dev/null
+++ b/cli/scripts/cli.sh
@@ -0,0 +1,37 @@
+#!/bin/bash
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+
+# check if java install
+if [ -z "$JAVA_HOME" -o ! -f "$JAVA_HOME/bin/java" ]; then
+ echo Error: JAVA_HOME invalid in your environment. >&2
+ echo Please set the JAVA_HOME variable in your environment to match the >&2
+ echo location of your Java installation. >&2
+ exit 1
+fi
+
+shellDir=$(dirname $(readlink -f "$0"))
+
+# check if jar file exist
+jarFile=$(find ${shellDir} -name "cli-*.jar" | head -n 1)
+
+if [[ ! -f ${jarFile} ]]; then
+ echo "error: cli.jar not exist. make sure it is placed in the current directory or subdirectory of this script"
+ exit 1
+fi
+
+java -jar ${jarFile} $*
diff --git a/toolkit-distribution/src/assembly/bin.xml b/toolkit-distribution/src/assembly/bin.xml
index 2c1ff53..25565b9 100644
--- a/toolkit-distribution/src/assembly/bin.xml
+++ b/toolkit-distribution/src/assembly/bin.xml
@@ -42,6 +42,14 @@
<include>licenses/**</include>
</includes>
</fileSet>
+ <fileSet>
+ <directory>../cli/scripts</directory>
+ <outputDirectory>/</outputDirectory>
+ <includes>
+ <include>cli.sh</include>
+ <include>cli.cmd</include>
+ </includes>
+ </fileSet>
</fileSets>
<dependencySets>
<dependencySet>