Skip to content

Commit ce1fcc2

Browse files
authored
adjust doc gen to support the usage title and usage description (#1932)
* adjust doc gen to support the usage title and usage description * adjust README.md
1 parent e201149 commit ce1fcc2

File tree

50 files changed

+174
-118
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+174
-118
lines changed

gendoc/README.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DataSourcesMap: map[string]*schema.Resource{
3838
description 包括一个用于表头的一句话描述,与一个用于正文的详细说明。
3939
example usage 则是一个或几个使用示例。
4040

41-
description & example usage 需要在对应 resource 及 data_source 定义的文件中出现,它是符合 golang 标准文档注释的写法。例如:
41+
description & example usage & usage description 需要在对应 resource 及 data_source 定义的文件中出现,它是符合 golang 标准文档注释的写法。例如:
4242

4343
/*
4444
Use this data source to get information about a MySQL instance.
@@ -47,6 +47,21 @@ description & example usage 需要在对应 resource 及 data_source 定义的
4747
\n
4848
Example Usage
4949
\n
50+
Scenario1 title
51+
\n
52+
Description of the Scenario1
53+
\n
54+
```hcl
55+
data "tencentcloud_mysql_instance" "database"{
56+
mysql_id = "my-test-database"
57+
result_output_file = "mytestpath"
58+
}
59+
```
60+
\n
61+
Scenario2 title
62+
\n
63+
Description of the Scenario2
64+
\n
5065
```hcl
5166
data "tencentcloud_mysql_instance" "database"{
5267
mysql_id = "my-test-database"
@@ -65,7 +80,16 @@ description & example usage 需要在对应 resource 及 data_source 定义的
6580
\n
6681
Example Usage
6782
\n
68-
Example Usage 是必须的,在 Example Usage 以下的内容都会当成 Example Usage 填充到文档中。
83+
Example Usage 是必须的,在 Example Usage 以下的内容都会填充到文档中。
84+
Example Usage 由一个到多个Scenario(场景)构成。
85+
每个Scenario 由 Scenario title 和 Scenario description 构成。
86+
\n
87+
Usage1 title
88+
\n
89+
Description of the Usage1
90+
\n
91+
Scenario title 是必须的。
92+
Scenario description 是可选的,可以根据情况填写。
6993
*/
7094
package tencentcloud
7195

gendoc/main.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ const (
2828
)
2929

3030
var (
31-
hclMatch = regexp.MustCompile("(?si)([^`]+)?```(hcl)?(.*?)```")
32-
bigSymbol = regexp.MustCompile("([\u007F-\uffff])")
31+
hclMatch = regexp.MustCompile("(?si)([^`]+)?```(hcl)?(.*?)```")
32+
usageMatch = regexp.MustCompile(`(?s)(?m)^([^ \n].*?)(?:\n{2}|$)(.*)`)
33+
bigSymbol = regexp.MustCompile("([\u007F-\uffff])")
3334
)
3435

3536
func main() {
@@ -407,16 +408,32 @@ func formatHCL(s string) string {
407408
for _, v := range m {
408409
p := strings.TrimSpace(v[1])
409410
if p != "" {
410-
p = fmt.Sprintf("\n%s\n\n", p)
411+
p = formatUsageDesc(p)
411412
}
412413
b := hclwrite.Format([]byte(strings.TrimSpace(v[3])))
413-
rr = append(rr, fmt.Sprintf("%s```hcl\n%s\n```", p, string(b)))
414+
rr = append(rr, fmt.Sprintf("\n%s\n\n```hcl\n%s\n```", p, string(b)))
414415
}
415416
}
416417

417418
return strings.TrimSpace(strings.Join(rr, "\n"))
418419
}
419420

421+
func formatUsageDesc(s string) string {
422+
var rr []string
423+
s = strings.TrimSpace(s)
424+
m := usageMatch.FindAllStringSubmatch(s, -1)
425+
426+
for _, v := range m {
427+
title := strings.TrimSpace(v[1])
428+
descp := strings.TrimSpace(v[2])
429+
430+
rr = append(rr, fmt.Sprintf("### %s\n\n%s", title, descp))
431+
}
432+
433+
ret := strings.TrimSpace(strings.Join(rr, "\n\n"))
434+
return ret
435+
}
436+
420437
// checkDescription check description format
421438
func checkDescription(k, s string) {
422439
if s == "" {

website/docs/d/cbs_storages.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ data "tencentcloud_cbs_storages" "storages" {
2020
}
2121
```
2222

23-
The following snippet shows the new supported query params
23+
### The following snippet shows the new supported query params
2424

2525
```hcl
2626
data "tencentcloud_cbs_storages" "whats_new" {

website/docs/d/cynosdb_instance_slow_queries.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use this data source to query detailed information of cynosdb instance_slow_quer
1313

1414
## Example Usage
1515

16-
Query slow queries of instance
16+
### Query slow queries of instance
1717

1818
```hcl
1919
variable "cynosdb_cluster_id" {
@@ -32,7 +32,7 @@ data "tencentcloud_cynosdb_instance_slow_queries" "instance_slow_queries" {
3232
}
3333
```
3434

35-
Query slow queries by time range
35+
### Query slow queries by time range
3636

3737
```hcl
3838
variable "cynosdb_cluster_id" {
@@ -48,7 +48,7 @@ data "tencentcloud_cynosdb_instance_slow_queries" "instance_slow_queries" {
4848
}
4949
```
5050

51-
Query slow queries by user and db name
51+
### Query slow queries by user and db name
5252

5353
```hcl
5454
variable "cynosdb_cluster_id" {

website/docs/d/dbbrain_top_space_tables.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use this data source to query detailed information of dbbrain top_space_tables
1313

1414
## Example Usage
1515

16-
Sort by PhysicalFileSize
16+
### Sort by PhysicalFileSize
1717

1818
```hcl
1919
data "tencentcloud_dbbrain_top_space_tables" "top_space_tables" {
@@ -23,7 +23,7 @@ data "tencentcloud_dbbrain_top_space_tables" "top_space_tables" {
2323
}
2424
```
2525

26-
Sort by TotalLength
26+
### Sort by TotalLength
2727

2828
```hcl
2929
data "tencentcloud_dbbrain_top_space_tables" "top_space_tables" {

website/docs/d/dnspod_records.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ output "result" {
2424
}
2525
```
2626

27-
Use verbose filter
27+
### Use verbose filter
2828

2929
```hcl
3030
data "tencentcloud_dnspod_records" "record" {

website/docs/r/api_gateway_service.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use this resource to create API gateway service.
1313

1414
## Example Usage
1515

16-
Shared Service
16+
### Shared Service
1717

1818
```hcl
1919
resource "tencentcloud_api_gateway_service" "service" {
@@ -32,7 +32,7 @@ resource "tencentcloud_api_gateway_service" "service" {
3232
}
3333
```
3434

35-
Exclusive Service
35+
### Exclusive Service
3636

3737
```hcl
3838
resource "tencentcloud_api_gateway_service" "service" {

website/docs/r/as_scaling_config.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ resource "tencentcloud_as_scaling_config" "launch_configuration" {
4343
}
4444
```
4545

46-
Using SPOT charge type
46+
### Using SPOT charge type
4747

4848
```hcl
4949
resource "tencentcloud_as_scaling_config" "launch_configuration" {

website/docs/r/cam_role.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Provides a resource to create a CAM role.
1313

1414
## Example Usage
1515

16-
Create normally
16+
### Create normally
1717

1818
```hcl
1919
resource "tencentcloud_cam_role" "foo" {
@@ -40,7 +40,7 @@ EOF
4040
}
4141
```
4242

43-
Create with SAML provider
43+
### Create with SAML provider
4444

4545
```hcl
4646
resource "tencentcloud_cam_role" "boo" {

website/docs/r/ccn.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Provides a resource to create a CCN instance.
1313

1414
## Example Usage
1515

16-
Create a prepaid CCN
16+
### Create a prepaid CCN
1717

1818
```hcl
1919
resource "tencentcloud_ccn" "main" {
@@ -25,7 +25,7 @@ resource "tencentcloud_ccn" "main" {
2525
}
2626
```
2727

28-
Create a post-paid regional export speed limit type CCN
28+
### Create a post-paid regional export speed limit type CCN
2929

3030
```hcl
3131
resource "tencentcloud_ccn" "main" {
@@ -37,7 +37,7 @@ resource "tencentcloud_ccn" "main" {
3737
}
3838
```
3939

40-
Create a post-paid inter-regional rate limit type CNN
40+
### Create a post-paid inter-regional rate limit type CNN
4141

4242
```hcl
4343
resource "tencentcloud_ccn" "main" {

0 commit comments

Comments
 (0)