Skip to content

Commit

Permalink
Merge pull request #182 from opsnull/main
Browse files Browse the repository at this point in the history
fix: wrong examples in tour.md and faq-acl.md
  • Loading branch information
Peefy authored Oct 17, 2023
2 parents 2047e9a + d0c5593 commit 1d29179
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 56 deletions.
23 changes: 12 additions & 11 deletions docs/reference/lang/tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -1704,10 +1704,10 @@ schema Data2:
data: Data1 | Data2 = Data1 {}
if typeof(a) == "Data1":
data1 = data as Data1 # The type of `data1` is `Data1`
elif typeof(a) == "Data2":
data2 = data as Data2 # The type of `data2` is `Data2`
if typeof(data) == "Data1":
data1 = data as Data1 # The type of `data` is `Data1`
elif typeof(data) == "Data2":
data2 = data as Data2 # The type of `data` is `Data2`
```
When a runtime error occurs in the `as` type conversion, a runtime error is thrown.
Expand Down Expand Up @@ -2546,11 +2546,11 @@ Examples:

```python
schema Data:
labels: {str:} = {key1 = [0]}
labels: {str:} = {key1 = [0, 1, 3]}
data = Data {
# insert [1] into the attribute labels.key1 of the schema Data.
labels: {key1 += [1]}
# insert [2] after the index 1 of the attribute labels.key1 of the schema Data.
labels: {key1[1] += [2]}
}
```

Expand All @@ -2562,6 +2562,8 @@ data:
key1:
- 0
- 1
- 2
- 3
```

If no index is specified, the last index will be used.
Expand Down Expand Up @@ -2650,12 +2652,12 @@ rule2 = SomeRule {} # Rule call
We can use protocol to implement type checking of rule structure:

```python
# Schema definition
# Protocol definition
protocol Service:
clusterIp: str
$type: str

# Schema definition
# Protocol definition
protocol Volume:
mountPath: [str]

Expand Down Expand Up @@ -3003,7 +3005,7 @@ Parameters
- **key**: The argument key.
- **type**: The argument type to be converted.
- **default**: The argument default value when the key-value argument is not provided
- **required**: Report an error when the key-value argument is not provided and required is True.
- **required**: Report an error when the key-value argument is not provided and required is True, but don't provide the default value.
- **help**: The help message.

### Multi-file Compilation
Expand Down Expand Up @@ -3320,7 +3322,6 @@ The output is

```yaml
config:
x: 1
y: s
```

Expand Down
4 changes: 2 additions & 2 deletions docs/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -1506,8 +1506,8 @@ The most commonly used attribute operator is `=`, which indicates the assignment
```python
data = { # define a dictionary type variable data
a = 1 # use = to declare a attribute a in data with a value of 1
b = 2 # use = to declare a attribute b in data with a value of 1
} # The final data value is {"a": 1, "b": 1}
b = 2 # use = to declare a attribute b in data with a value of 2
} # The final data value is {"a": 1, "b": 2}
```

we can also use the override attribute operator at the schema instantiation to achieve the effect of overriding the default value of the schema. Generally, when creating a new schema instance, if there is no special requirement, we can generally use `=`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1702,10 +1702,10 @@ schema Data2:
data: Data1 | Data2 = Data1 {}
if typeof(a) == "Data1":
data1 = data as Data1 # The type of `data1` is `Data1`
elif typeof(a) == "Data2":
data2 = data as Data2 # The type of `data2` is `Data2`
if typeof(data) == "Data1":
data1 = data as Data1 # The type of `data` is `Data1`
elif typeof(data) == "Data2":
data2 = data as Data2 # The type of `data` is `Data2`
```
当类型转换失败时,一个运行时错误将被抛出。
Expand Down Expand Up @@ -2482,11 +2482,11 @@ data:

```python
schema Data:
labels: {str:} = {key1 = [0]}
labels: {str:} = {key1 = [0, 1, 3]}
data = Data {
# insert [1] into the attribute labels.key1 of the schema Data.
labels: {key1 += [1]}
# insert [3] after the index 1 of the attribute labels.key1 of the schema Data.
labels: {key1[1] += [2]}
}
```

Expand All @@ -2498,6 +2498,8 @@ data:
key1:
- 0
- 1
- 2
- 3
```

如果没有定义索引,将使用最后一个索引。
Expand Down Expand Up @@ -2569,12 +2571,12 @@ rule2 = SomeRule {}
可以使用 protocol 和 for 绑定语句为 rule 增加类型约束:

```python
# Schema definition
# Protocol definition
protocol Service:
clusterIp: str
$type: str

# Schema definition
# Protocol definition
protocol Volume:
mountPath: [str]

Expand Down Expand Up @@ -2708,7 +2710,7 @@ allow = Allow() or False

### 模块

KCL 配置文件以 **模块** 形式组织。 单个 KCL 文件被认为是一个 module,一个目录被认为是一个包。
KCL 配置文件以 **模块 (module)** 形式组织。 单个 KCL 文件被认为是一个模块,一个目录被认为是一个包。

同一个包内的模块是可见的,跨包引用需要通过导入可见。

Expand Down Expand Up @@ -2918,7 +2920,7 @@ value = option(key="key", type='str', default="default_value", required=True, he
- **key**: 参数的键。
- **type**: 要转换的参数类型。
- **default**: 参数默认值。
- **required**: 当未提供参数且参数的 required 为 True 是报告错误
- **required**: 当未提供参数和缺省值,且参数的 required 为 True 时报告错误
- **help**: 帮助信息。

### 多文件编译
Expand Down Expand Up @@ -3210,7 +3212,6 @@ kcl main.k -O config.x-

```yaml
config:
x: 1
y: s
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ KCL 中使用 `?` 运算符定义一个 schema 的"可选"约束,schema 属性
schema Person:
firstName?: str # firstName是一个可选属性,可以赋值为None/Undefined
lastName?: str # age是一个可选属性,可以赋值为None/Undefined
# age属性的默认值为0
# age属性的默认值为 18
age: int = 18 # age是一个必选属性,不能赋值为None/Undefined,并且是一个不可变属性
age = 10 # Error, age是一个不可变的属性
```
Expand Down Expand Up @@ -1518,8 +1518,8 @@ print({k1 = 1, k2 = 2, k3 = 3} == {k2 = 2, k1 = 1}) # False
```python
data = { # 定义一个字典类型的变量 data
a = 1 # 使用 = 在 data 中声明一个值为 1 的属性 a
b = 2 # 使用 = 在 data 中声明一个值为 1 的属性 b
} # 最终 data 的值为 {"a": 1, "b": 1}
b = 2 # 使用 = 在 data 中声明一个值为 2 的属性 b
} # 最终 data 的值为 {"a": 1, "b": 2}
```

在 schema 实例化处也可以使用覆盖属性运算符实现对 schema 默认值的覆盖效果,一般在创建新的 schema 实例时如无特殊的需求,一般使用 `=` 即可
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1702,10 +1702,10 @@ schema Data2:
data: Data1 | Data2 = Data1 {}
if typeof(a) == "Data1":
data1 = data as Data1 # The type of `data1` is `Data1`
elif typeof(a) == "Data2":
data2 = data as Data2 # The type of `data2` is `Data2`
if typeof(data) == "Data1":
data1 = data as Data1 # The type of `data` is `Data1`
elif typeof(data) == "Data2":
data2 = data as Data2 # The type of `data` is `Data2`
```
当类型转换失败时,一个运行时错误将被抛出。
Expand Down Expand Up @@ -2482,11 +2482,11 @@ data:

```python
schema Data:
labels: {str:} = {key1 = [0]}
labels: {str:} = {key1 = [0, 1, 3]}
data = Data {
# insert [1] into the attribute labels.key1 of the schema Data.
labels: {key1 += [1]}
# insert [2] after the index 1 of the attribute labels.key1 of the schema Data.
labels: {key1[1] += [2]}
}
```

Expand All @@ -2498,6 +2498,8 @@ data:
key1:
- 0
- 1
- 2
- 3
```

如果没有定义索引,将使用最后一个索引。
Expand Down Expand Up @@ -2569,12 +2571,12 @@ rule2 = SomeRule {}
可以使用 protocol 和 for 绑定语句为 rule 增加类型约束:

```python
# Schema definition
# Protocol definition
protocol Service:
clusterIp: str
$type: str

# Schema definition
# Protocol definition
protocol Volume:
mountPath: [str]

Expand Down Expand Up @@ -2708,7 +2710,7 @@ allow = Allow() or False

### 模块

KCL 配置文件以 **模块** 形式组织。 单个 KCL 文件被认为是一个 module,一个目录被认为是一个包。
KCL 配置文件以 **模块(module)** 形式组织。 单个 KCL 文件被认为是一个模块,一个目录被认为是一个包。

同一个包内的模块是可见的,跨包引用需要通过导入可见。

Expand Down Expand Up @@ -2918,7 +2920,7 @@ value = option(key="key", type='str', default="default_value", required=True, he
- **key**: 参数的键。
- **type**: 要转换的参数类型。
- **default**: 参数默认值。
- **required**: 当未提供参数且参数的 required 为 True 是报告错误
- **required**: 当未提供参数和缺省值,且参数的 required 为 True 时报告错误
- **help**: 帮助信息。

### 多文件编译
Expand Down Expand Up @@ -3210,7 +3212,6 @@ kcl main.k -O config.x-

```yaml
config:
x: 1
y: s
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ KCL 中使用 `?` 运算符定义一个 schema 的"可选"约束,schema 属性
schema Person:
firstName?: str # firstName是一个可选属性,可以赋值为None/Undefined
lastName?: str # age是一个可选属性,可以赋值为None/Undefined
# age属性的默认值为0
# age属性的默认值为 18
age: int = 18 # age是一个必选属性,不能赋值为None/Undefined,并且是一个不可变属性
age = 10 # Error, age是一个不可变的属性
```
Expand Down Expand Up @@ -1518,8 +1518,8 @@ print({k1 = 1, k2 = 2, k3 = 3} == {k2 = 2, k1 = 1}) # False
```python
data = { # 定义一个字典类型的变量 data
a = 1 # 使用 = 在 data 中声明一个值为 1 的属性 a
b = 2 # 使用 = 在 data 中声明一个值为 1 的属性 b
} # 最终 data 的值为 {"a": 1, "b": 1}
b = 2 # 使用 = 在 data 中声明一个值为 2 的属性 b
} # 最终 data 的值为 {"a": 1, "b": 2}
```

在 schema 实例化处也可以使用覆盖属性运算符实现对 schema 默认值的覆盖效果,一般在创建新的 schema 实例时如无特殊的需求,一般使用 `=` 即可
Expand Down
23 changes: 12 additions & 11 deletions versioned_docs/version-0.6.0/reference/lang/tour.md
Original file line number Diff line number Diff line change
Expand Up @@ -1704,10 +1704,10 @@ schema Data2:
data: Data1 | Data2 = Data1 {}
if typeof(a) == "Data1":
data1 = data as Data1 # The type of `data1` is `Data1`
elif typeof(a) == "Data2":
data2 = data as Data2 # The type of `data2` is `Data2`
if typeof(data) == "Data1":
data1 = data as Data1 # The type of `data` is `Data1`
elif typeof(data) == "Data2":
data2 = data as Data2 # The type of `data` is `Data2`
```
When a runtime error occurs in the `as` type conversion, a runtime error is thrown.
Expand Down Expand Up @@ -2546,11 +2546,11 @@ Examples:

```python
schema Data:
labels: {str:} = {key1 = [0]}
labels: {str:} = {key1 = [0, 1, 3]}
data = Data {
# insert [1] into the attribute labels.key1 of the schema Data.
labels: {key1 += [1]}
# insert [2] after the index 1 of the attribute labels.key1 of the schema Data.
labels: {key1 += [2]}
}
```

Expand All @@ -2562,6 +2562,8 @@ data:
key1:
- 0
- 1
- 2
- 3
```

If no index is specified, the last index will be used.
Expand Down Expand Up @@ -2650,12 +2652,12 @@ rule2 = SomeRule {} # Rule call
We can use protocol to implement type checking of rule structure:

```python
# Schema definition
# Protocol definition
protocol Service:
clusterIp: str
$type: str

# Schema definition
# Protocol definition
protocol Volume:
mountPath: [str]

Expand Down Expand Up @@ -3003,7 +3005,7 @@ Parameters
- **key**: The argument key.
- **type**: The argument type to be converted.
- **default**: The argument default value when the key-value argument is not provided
- **required**: Report an error when the key-value argument is not provided and required is True.
- **required**: Report an error when the key-value argument is not provided and required is True, but don't provide the default value.
- **help**: The help message.

### Multi-file Compilation
Expand Down Expand Up @@ -3320,7 +3322,6 @@ The output is

```yaml
config:
x: 1
y: s
```

Expand Down
4 changes: 2 additions & 2 deletions versioned_docs/version-0.6.0/user_docs/support/faq-kcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -1506,8 +1506,8 @@ The most commonly used attribute operator is `=`, which indicates the assignment
```python
data = { # define a dictionary type variable data
a = 1 # use = to declare a attribute a in data with a value of 1
b = 2 # use = to declare a attribute b in data with a value of 1
} # The final data value is {"a": 1, "b": 1}
b = 2 # use = to declare a attribute b in data with a value of 2
} # The final data value is {"a": 1, "b": 2}
```

we can also use the override attribute operator at the schema instantiation to achieve the effect of overriding the default value of the schema. Generally, when creating a new schema instance, if there is no special requirement, we can generally use `=`
Expand Down

0 comments on commit 1d29179

Please sign in to comment.