Skip to content

Commit

Permalink
Merge 8d8a35d into 035fecf
Browse files Browse the repository at this point in the history
  • Loading branch information
kakulisen committed Dec 13, 2019
2 parents 035fecf + 8d8a35d commit 754728d
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 17 deletions.
24 changes: 16 additions & 8 deletions README-ZH.md
Expand Up @@ -234,13 +234,21 @@ mvn toolkit:verify


### 3.3 使用toolkit cli工具
可执行jar包位于toolkit/cli/target/bin目录下

#### 3.3.0 获取
* 如果你使用的是正式发布版本(>=0.2.0),可以在解压二进制包后直接使用里面的脚本文件
* 在Linux及Mac环境,请使用cli.sh
* 在Windows环境,请使用cli.cmd

* 如果你是通过源码构建,可以将`cli/scripts/cli.*``cli/target/bin/toolkit-cli-{version}.jar`放置在同一目录,然后根据不同环境选择不同脚本

以下所有示例均通过Linux环境的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
Expand All @@ -266,7 +274,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格式,支持指定本地和网络文件
Expand All @@ -279,9 +287,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
Expand All @@ -293,9 +301,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
Expand Down
21 changes: 13 additions & 8 deletions README.md
Expand Up @@ -229,13 +229,18 @@ 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 the script files directly after decompressing the binary package
* In Linux and Mac environment, please use cli.sh
* In the Windows environment, please use cli.cmd
* If you are building from source, you can put `cli/scripts/cli.*` in the same directory as`cli/target/bin/toolkit-cli-{version}.jar` and then choose different scripts according to different environments

All the examples below are introduced through cli.sh for Linux environment
```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.
Expand All @@ -261,7 +266,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.
Expand All @@ -274,9 +279,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
Expand All @@ -288,9 +293,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
Expand Down
67 changes: 67 additions & 0 deletions 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 -Dscript.name="cli.cmd" -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%
50 changes: 50 additions & 0 deletions cli/scripts/cli.sh
@@ -0,0 +1,50 @@
#!/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

# resolve links - $0 may be a softlink
PRG="$0"

while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`/"$link"
fi
done

shellDir=`dirname "$PRG"`

# 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 -Dscript.name="cli.sh" -jar ${jarFile} $*
Expand Up @@ -21,6 +21,8 @@
import java.util.Optional;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;

import io.airlift.airline.Cli;
import io.airlift.airline.Help;

Expand All @@ -33,7 +35,14 @@ public static void main(String[] args) {

initialProjectVersion();

Cli.CliBuilder<Runnable> builder = Cli.<Runnable>builder("java -jar toolkit-cli-" + projectVersion + ".jar");
String scriptName = System.getProperty("script.name");
Cli.CliBuilder<Runnable> builder = null;
if (StringUtils.isNotEmpty(scriptName)) {
builder = Cli.builder(scriptName);
} else {
builder = Cli.builder("java -jar toolkit-cli-" + projectVersion + ".jar");
}

builder.withDescription("Microservice development toolkit(version " + projectVersion
+ "). ");
builder.withDefaultCommand(Help.class);
Expand Down
8 changes: 8 additions & 0 deletions toolkit-distribution/src/assembly/bin.xml
Expand Up @@ -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>
Expand Down

0 comments on commit 754728d

Please sign in to comment.