docs: 优化文档展示,适配部分无目录文档,适配非结构体的类型定义,增加测试用例文档
This commit is contained in:
@@ -1,27 +1,22 @@
|
||||
# Main
|
||||
|
||||
|
||||
|
||||
[](https://pkg.go.dev/github.com/kercylan98/minotaur/main)
|
||||

|
||||
|
||||
## 目录
|
||||
列出了该 `package` 下所有的函数,可通过目录进行快捷跳转 ❤️
|
||||
|
||||
|
||||
|
||||
## 目录导航
|
||||
列出了该 `package` 下所有的函数及类型定义,可通过目录导航进行快捷跳转 ❤️
|
||||
<details>
|
||||
<summary>展开 / 折叠目录</summary
|
||||
<summary>展开 / 折叠目录导航</summary>
|
||||
|
||||
|
||||
> 包级函数定义
|
||||
|
||||
|函数|描述
|
||||
|函数名称|描述
|
||||
|:--|:--
|
||||
|
||||
|
||||
> 结构体定义
|
||||
|
||||
|结构体|描述
|
||||
|:--|:--
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
***
|
||||
## 详情信息
|
||||
|
||||
@@ -1,32 +1,113 @@
|
||||
# Cmd
|
||||
|
||||
|
||||
|
||||
[](https://pkg.go.dev/github.com/kercylan98/minotaur/cmd)
|
||||

|
||||
|
||||
## 目录
|
||||
列出了该 `package` 下所有的函数,可通过目录进行快捷跳转 ❤️
|
||||
|
||||
|
||||
|
||||
## 目录导航
|
||||
列出了该 `package` 下所有的函数及类型定义,可通过目录导航进行快捷跳转 ❤️
|
||||
<details>
|
||||
<summary>展开 / 折叠目录</summary
|
||||
<summary>展开 / 折叠目录导航</summary>
|
||||
|
||||
|
||||
> 包级函数定义
|
||||
|
||||
|函数|描述
|
||||
|函数名称|描述
|
||||
|:--|:--
|
||||
|[Execute](#Execute)|将所有子命令添加到根命令并适当设置标志。这是由 main.main() 调用的。 rootCmd 只需要发生一次
|
||||
|
||||
|
||||
> 结构体定义
|
||||
***
|
||||
## 详情信息
|
||||
#### func Execute()
|
||||
<span id="Execute"></span>
|
||||
> 将所有子命令添加到根命令并适当设置标志。这是由 main.main() 调用的。 rootCmd 只需要发生一次
|
||||
|
||||
<details>
|
||||
<summary>查看 / 收起单元测试</summary>
|
||||
|
||||
|
||||
```go
|
||||
|
||||
func TestExecute(t *testing.T) {
|
||||
var filePath, outPath, exclude, exportType, prefix string
|
||||
exportType = "s"
|
||||
filePath = `.\游戏配置.xlsx`
|
||||
filePath = `../xlsx_template.xlsx`
|
||||
outPath = `.`
|
||||
isDir, err := file.IsDir(outPath)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
isDir = filepath.Ext(outPath) == ""
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
if !isDir {
|
||||
panic(errors.New("output must be a directory path"))
|
||||
}
|
||||
_ = os.MkdirAll(outPath, os.ModePerm)
|
||||
fpd, err := file.IsDir(filePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
var xlsxFiles []string
|
||||
if fpd {
|
||||
files, err := os.ReadDir(filePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, f := range files {
|
||||
if f.IsDir() || !strings.HasSuffix(f.Name(), ".xlsx") || strings.HasPrefix(f.Name(), "~") {
|
||||
continue
|
||||
}
|
||||
xlsxFiles = append(xlsxFiles, filepath.Join(filePath, f.Name()))
|
||||
}
|
||||
} else {
|
||||
xlsxFiles = append(xlsxFiles, filePath)
|
||||
}
|
||||
var exporter = pce.NewExporter()
|
||||
loader := pce.NewLoader(pce.GetFields())
|
||||
excludes := collection.ConvertSliceToBoolMap(str.SplitTrimSpace(exclude, ","))
|
||||
for _, xlsxFile := range xlsxFiles {
|
||||
xf, err := xlsx.OpenFile(xlsxFile)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
for _, sheet := range xf.Sheets {
|
||||
var cx *cs.Xlsx
|
||||
switch strings.TrimSpace(strings.ToLower(exportType)) {
|
||||
case "c":
|
||||
cx = cs.NewXlsx(sheet, cs.XlsxExportTypeClient)
|
||||
case "s":
|
||||
cx = cs.NewXlsx(sheet, cs.XlsxExportTypeServer)
|
||||
}
|
||||
if strings.HasPrefix(cx.GetDisplayName(), "#") || strings.HasPrefix(cx.GetConfigName(), "#") || excludes[cx.GetConfigName()] || excludes[cx.GetDisplayName()] {
|
||||
continue
|
||||
}
|
||||
if raw, err := exporter.ExportData(tmpls.NewJSON(), loader.LoadData(cx)); err != nil {
|
||||
panic(err)
|
||||
} else {
|
||||
var jsonPath string
|
||||
if len(prefix) == 0 {
|
||||
jsonPath = filepath.Join(outPath, fmt.Sprintf("%s.json", cx.GetConfigName()))
|
||||
} else {
|
||||
jsonPath = filepath.Join(outPath, fmt.Sprintf("%s.%s.json", prefix, cx.GetConfigName()))
|
||||
}
|
||||
if err := file.WriterFile(jsonPath, raw); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
|结构体|描述
|
||||
|:--|:--
|
||||
|
||||
</details>
|
||||
|
||||
|
||||
#### func Execute()
|
||||
<span id="Execute"></span>
|
||||
> 将所有子命令添加到根命令并适当设置标志。这是由 main.main() 调用的。 rootCmd 只需要发生一次
|
||||
***
|
||||
|
||||
Reference in New Issue
Block a user