Skip to content

feat: translate fmt #121

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

Merged
merged 3 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions docs/reference/cli/kcl/fmt.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,35 @@
sidebar_position: 2
---

# 格式化代码
# Format

KCL 支持通过内置的命令行工具一键格式化多个 KCL 文件文档。本文展示 KCL 编码风格和 KCL 格式化工具的使用方式。
KCL supports formatting multiple KCL files via built-in command line tools. This article demonstrates the KCL coding style and how to use the KCL formatting tool.

## KCL 编码风格
## Code Style

KCL 格式化对文件的修改样式具体见 KCL 编码风格:Style Guide for KCL Code
The KCL formatting tool modifies the files according to the KCL coding style: [Style Guide for KCL Code](../../lang/lang/spec/codestyle.md)

## 使用方式
## How to use

* 单文件格式化
* Formatting Single File

```text
kcl-fmt your_config.k
```

* 文件夹内多文件格式化
* Formatting multiple files

```text
kcl-fmt your_config_path -R
```

* 命令行参数
* `-R|--recursive` 设置是否递归遍历子文件夹
* `-w|--fmt-output` 设置是否输出到标准输出流,不加 `-w` 表示原地格式化 KCL 文件
* Args
* `-R|--recursive` Whether to recursively traverse subfolders
* `-w|--fmt-output` Whether to output to STDOUT, without `-w` means in-place modification.

## 格式化文件效果展示
## Display of formatting files

* 格式化前
* Before formatting

```py
import math
Expand All @@ -47,7 +47,7 @@ schema Deployment[replicas] ( DeploymentBase ) :
deploy = Deployment(replicas = 3){}
```

* 格式化后
* After formatting

```py
import math
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "命令行工具",
"position": 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"label": "KCL 语言工具",
"position": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
sidebar_position: 2
---

# 格式化代码

KCL 支持通过内置的命令行工具一键格式化多个 KCL 文件文档。本文展示 KCL 编码风格和 KCL 格式化工具的使用方式。

## KCL 编码风格

KCL 格式化对文件的修改样式具体见 KCL 编码风格:[Style Guide for KCL Code](../../lang/lang/spec/codestyle.md)

## 使用方式

* 单文件格式化

```text
kcl-fmt your_config.k
```

* 文件夹内多文件格式化

```text
kcl-fmt your_config_path -R
```

* 命令行参数
* `-R|--recursive` 设置是否递归遍历子文件夹
* `-w|--fmt-output` 设置是否输出到标准输出流,不加 `-w` 表示原地格式化 KCL 文件

## 格式化文件效果展示

* 格式化前

```py
import math
mixin DeploymentMixin:
service:str ="my-service"
schema DeploymentBase:
name: str
image : str
schema Deployment[replicas] ( DeploymentBase ) :
mixin[DeploymentMixin]
replicas : int = replicas
command: [str ]
labels: {str: str}
deploy = Deployment(replicas = 3){}
```

* 格式化后

```py
import math

mixin DeploymentMixin:
service: str = "my-service"

schema DeploymentBase:
name: str
image: str

schema Deployment[replicas](DeploymentBase):
mixin [DeploymentMixin]
replicas: int = replicas
command: [str]
labels: {str:str}

deploy = Deployment(replicas=3) {}

```