Skip to content

Commit 0690f4b

Browse files
authored
Merge pull request #401 from Peefy/update-faq-documents
chore: update and format faq documents
2 parents 929f8a6 + b2c9f84 commit 0690f4b

File tree

15 files changed

+325
-195
lines changed

15 files changed

+325
-195
lines changed

docs/reference/lang/tour.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ assert x.upper() == "LENGTH"
362362

363363
There are 2 different ways to format a string: to use the `"{}".format()` built-in function, or to specify the variable between the curly braces and use a `${}` mark to tell KCL to extract its value. This is called **string interpolation** in KCL. In following example, both `a` and `b` will be assigned to string `"hello world"`.
364364

365-
Besides, the variable to serialized can be extracted in special data format, such as YAML or JSON. In this case, a `#yaml` or `#json` can be included within the curly braces.
365+
Besides, the variable to serialized can be extracted in special data format, such as YAML or JSON. In this case, a `#yaml` or `#json` can be included within the curly braces.
366366

367367
Note that if we don't want to interpolate variables, we can add the `\` character before `$`.
368368

docs/user_docs/guides/working-with-konfig/3-quick-start.md

+42-42
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,24 @@ spec:
6969
app.k8s.io/component: sampleappdev
7070
spec:
7171
containers:
72-
- env:
73-
- name: MY_ENV
74-
value: MY_VALUE
75-
image: nginx:1.7.8
76-
name: main
77-
ports:
78-
- containerPort: 80
79-
protocol: TCP
80-
resources:
81-
limits:
82-
cpu: '100m'
83-
memory: '100Mi'
84-
ephemeral-storage: '1Gi'
85-
requests:
86-
cpu: '100m'
87-
memory: '100Mi'
88-
ephemeral-storage: '1Gi'
89-
volumeMounts: []
72+
- env:
73+
- name: MY_ENV
74+
value: MY_VALUE
75+
image: nginx:1.7.8
76+
name: main
77+
ports:
78+
- containerPort: 80
79+
protocol: TCP
80+
resources:
81+
limits:
82+
cpu: "100m"
83+
memory: "100Mi"
84+
ephemeral-storage: "1Gi"
85+
requests:
86+
cpu: "100m"
87+
memory: "100Mi"
88+
ephemeral-storage: "1Gi"
89+
volumeMounts: []
9090
---
9191
apiVersion: v1
9292
kind: Namespace
@@ -100,9 +100,9 @@ metadata:
100100
namespace: sampleapp
101101
spec:
102102
ports:
103-
- nodePort: 30201
104-
port: 80
105-
targetPort: 80
103+
- nodePort: 30201
104+
port: 80
105+
targetPort: 80
106106
selector:
107107
app.kubernetes.io/name: sampleapp
108108
app.kubernetes.io/env: dev
@@ -157,24 +157,24 @@ spec:
157157
app.k8s.io/component: sampleappdev
158158
spec:
159159
containers:
160-
- env:
161-
- name: MY_ENV
162-
value: MY_VALUE
163-
image: nginx:latest
164-
name: main
165-
ports:
166-
- containerPort: 80
167-
protocol: TCP
168-
resources:
169-
limits:
170-
cpu: '100m'
171-
memory: '100Mi'
172-
ephemeral-storage: '1Gi'
173-
requests:
174-
cpu: '100m'
175-
memory: '100Mi'
176-
ephemeral-storage: '1Gi'
177-
volumeMounts: []
160+
- env:
161+
- name: MY_ENV
162+
value: MY_VALUE
163+
image: nginx:latest
164+
name: main
165+
ports:
166+
- containerPort: 80
167+
protocol: TCP
168+
resources:
169+
limits:
170+
cpu: "100m"
171+
memory: "100Mi"
172+
ephemeral-storage: "1Gi"
173+
requests:
174+
cpu: "100m"
175+
memory: "100Mi"
176+
ephemeral-storage: "1Gi"
177+
volumeMounts: []
178178
---
179179
apiVersion: v1
180180
kind: Namespace
@@ -188,9 +188,9 @@ metadata:
188188
namespace: sampleapp
189189
spec:
190190
ports:
191-
- nodePort: 30201
192-
port: 80
193-
targetPort: 80
191+
- nodePort: 30201
192+
port: 80
193+
targetPort: 80
194194
selector:
195195
app.kubernetes.io/name: sampleapp
196196
app.kubernetes.io/env: dev

docs/user_docs/support/faq-kcl.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -2650,17 +2650,17 @@ After you set the `KCL_CACHE_PATH`, when you run any KCL commands, the `.kclvm`
26502650

26512651
## 65. How to join a list to a string in KCL?
26522652

2653-
If we want to join a given list L = ['a', 'b', 'c'] into a string with some sepeartor (like a comma ",").
2653+
If we want to join a given list L = ['a', 'b', 'c'] into a string with some separator (like a comma ",").
26542654

2655-
```bash
2655+
```python
26562656
S = ",".join(['a', 'b', 'c'])
26572657
```
26582658

26592659
## 66. Is it possible to support schema lambda (class methods) in KCL?
26602660

26612661
KCL supports defining member functions for schemas and can omit them. An example KCL code is shown below for the same:
26622662

2663-
```KCL
2663+
```python
26642664
schema Person:
26652665
firstName: str
26662666
lastName: str
@@ -2677,7 +2677,7 @@ fullName = p.getFullName()
26772677

26782678
The above KCL code gives the output:
26792679

2680-
```bash
2680+
```yaml
26812681
p:
26822682
firstName: Alice
26832683
lastName: White
@@ -2688,7 +2688,7 @@ fullName: Alice White
26882688

26892689
You need to add specifically the type into the schema. An example code shown below:
26902690

2691-
```KCL
2691+
```python
26922692
schema FooBar:
26932693
mixin [
26942694
FooBarMixin
@@ -2709,7 +2709,7 @@ foobar = _c.foobar
27092709

27102710
returns the output:
27112711

2712-
```bash
2712+
```yaml
27132713
foobar: foo.bar
27142714
```
27152715

i18n/zh-CN/docusaurus-plugin-content-blog/2024-06-27-newsletter/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ image: /img/biweekly-newsletter.png
4646
- 三方库 victoria-metrics-operator 升级到 0.45.1 版本,新增了一些检查语句的提示信息。
4747
- 三方库 istio 升级到 1.21.2 版本,调整了一些 check 规则,新增了文档。
4848
- 三方库 jsonpatch 升级到 0.0.5 版本,支持 rfc6901Decode。
49-
49+
5050
**🏄 语言更新**
5151

5252
- 增加了 centos7 amd64 的构建环境。

i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/lang/codelab/schema.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ schema Deployment[priority]:
243243
_cpu = 1024
244244
else:
245245
_cpu = 2048
246-
246+
247247
cpu: int = _cpu
248248
memory: int = _cpu * 2
249249

i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/plugin/overview.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public class PluginTest {
157157
API.registerPlugin("my_plugin", Collections.singletonMap("add", (args, kwArgs) -> {
158158
return (int) args[0] + (int) args[1];
159159
}));
160-
160+
161161
API api = new API();
162162
ExecProgram_Result result = api
163163
.execProgram(ExecProgram_Args.newBuilder().addKFilenameList("test.k").build());

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/guides/working-with-konfig/3-quick-start.md

+45-45
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,24 @@ spec:
6969
app.k8s.io/component: sampleappdev
7070
spec:
7171
containers:
72-
- env:
73-
- name: MY_ENV
74-
value: MY_VALUE
75-
image: nginx:1.7.8
76-
name: main
77-
ports:
78-
- containerPort: 80
79-
protocol: TCP
80-
resources:
81-
limits:
82-
cpu: '100m'
83-
memory: '100Mi'
84-
ephemeral-storage: '1Gi'
85-
requests:
86-
cpu: '100m'
87-
memory: '100Mi'
88-
ephemeral-storage: '1Gi'
89-
volumeMounts: []
72+
- env:
73+
- name: MY_ENV
74+
value: MY_VALUE
75+
image: nginx:1.7.8
76+
name: main
77+
ports:
78+
- containerPort: 80
79+
protocol: TCP
80+
resources:
81+
limits:
82+
cpu: "100m"
83+
memory: "100Mi"
84+
ephemeral-storage: "1Gi"
85+
requests:
86+
cpu: "100m"
87+
memory: "100Mi"
88+
ephemeral-storage: "1Gi"
89+
volumeMounts: []
9090
---
9191
apiVersion: v1
9292
kind: Namespace
@@ -100,9 +100,9 @@ metadata:
100100
namespace: sampleapp
101101
spec:
102102
ports:
103-
- nodePort: 30201
104-
port: 80
105-
targetPort: 80
103+
- nodePort: 30201
104+
port: 80
105+
targetPort: 80
106106
selector:
107107
app.kubernetes.io/name: sampleapp
108108
app.kubernetes.io/env: dev
@@ -122,9 +122,9 @@ metadata:
122122
namespace: sampleapp
123123
spec:
124124
ports:
125-
- nodePort: 30201
126-
port: 80
127-
targetPort: 80
125+
- nodePort: 30201
126+
port: 80
127+
targetPort: 80
128128
selector:
129129
app.kubernetes.io/name: sampleapp
130130
app.kubernetes.io/env: prod
@@ -179,24 +179,24 @@ spec:
179179
app.k8s.io/component: sampleappdev
180180
spec:
181181
containers:
182-
- env:
183-
- name: MY_ENV
184-
value: MY_VALUE
185-
image: nginx:latest
186-
name: main
187-
ports:
188-
- containerPort: 80
189-
protocol: TCP
190-
resources:
191-
limits:
192-
cpu: '100m'
193-
memory: '100Mi'
194-
ephemeral-storage: '1Gi'
195-
requests:
196-
cpu: '100m'
197-
memory: '100Mi'
198-
ephemeral-storage: '1Gi'
199-
volumeMounts: []
182+
- env:
183+
- name: MY_ENV
184+
value: MY_VALUE
185+
image: nginx:latest
186+
name: main
187+
ports:
188+
- containerPort: 80
189+
protocol: TCP
190+
resources:
191+
limits:
192+
cpu: "100m"
193+
memory: "100Mi"
194+
ephemeral-storage: "1Gi"
195+
requests:
196+
cpu: "100m"
197+
memory: "100Mi"
198+
ephemeral-storage: "1Gi"
199+
volumeMounts: []
200200
---
201201
apiVersion: v1
202202
kind: Namespace
@@ -210,9 +210,9 @@ metadata:
210210
namespace: sampleapp
211211
spec:
212212
ports:
213-
- nodePort: 30201
214-
port: 80
215-
targetPort: 80
213+
- nodePort: 30201
214+
port: 80
215+
targetPort: 80
216216
selector:
217217
app.kubernetes.io/name: sampleapp
218218
app.kubernetes.io/env: dev

i18n/zh-CN/docusaurus-plugin-content-docs/current/user_docs/support/faq-kcl.md

+66-1
Original file line numberDiff line numberDiff line change
@@ -2627,7 +2627,72 @@ export KCL_CACHE_PATH=/tmp # 或者更改为您想要的路径
26272627
setx KCL_CACHE_PATH "C:\temp" /M
26282628
```
26292629

2630-
## 65. 如何在 KCL 中使用 "import another-module" ? 包名中包含横线 "-"
2630+
## 65. 如何在 KCL 中将列表连接成字符串?
2631+
2632+
如果我们想要将给定的列表 `L = ['a', 'b', 'c']` 用特定的分隔符(如逗号 ",")连接成一个字符串,可以使用以下 KCL 代码:
2633+
2634+
```python
2635+
S = ",".join(['a', 'b', 'c'])
2636+
```
2637+
2638+
## 66. 在 KCL 中是否支持 schema lambda(类方法)?
2639+
2640+
KCL 支持为 schema 使用 lambda 定义成员函数。下面是一个相关的KCL示例代码:
2641+
2642+
```python
2643+
schema Person:
2644+
firstName: str
2645+
lastName: str
2646+
getFullName: () -> str = lambda {
2647+
firstName + " " + lastName
2648+
}
2649+
2650+
p = Person{
2651+
firstName = "Alice"
2652+
lastName = "White"
2653+
}
2654+
fullName = p.getFullName()
2655+
```
2656+
2657+
上述 KCL 代码产生的输出:
2658+
2659+
```yaml
2660+
p:
2661+
firstName: Alice
2662+
lastName: White
2663+
fullName: Alice White
2664+
```
2665+
2666+
## 67. 在 mixin 外部使用混合属性是否需要转换为 any 类型?
2667+
2668+
需要将类型明确地添加到 schema 中即可使用混合属性。以下是一个示例代码:
2669+
2670+
```python
2671+
schema FooBar:
2672+
mixin [
2673+
FooBarMixin
2674+
]
2675+
foo: str = 'foo'
2676+
bar: str = 'bar'
2677+
2678+
protocol FooBarProtocol:
2679+
foo: str
2680+
bar: str
2681+
2682+
mixin FooBarMixin for FooBarProtocol:
2683+
foobar: str = "${foo}.${bar}" # 带有类型注解的属性可以在模式外部访问。
2684+
2685+
_c = FooBar {}
2686+
foobar = _c.foobar
2687+
```
2688+
2689+
输出为:
2690+
2691+
```yaml
2692+
foobar: foo.bar
2693+
```
2694+
2695+
## 68. 如何在 KCL 中使用 "import another-module" ? 包名中包含横线 "-"
26312696

26322697
在 KCL 中,import 语句中使用的模块名称中只支持`_`,kcl.mod 中的包名同时支持 `-` 和 `_`,KCL 编译器会自动将包名中的 `-` 替换为 `_`。
26332698

0 commit comments

Comments
 (0)