api format from stdin (#4772)

This commit is contained in:
kesonan
2025-05-02 15:59:47 +08:00
committed by GitHub
parent 789c5de873
commit e416d01f8d
2 changed files with 14 additions and 3 deletions

View File

@@ -42,8 +42,19 @@ var (
func GoFormatApi(_ *cobra.Command, _ []string) error { func GoFormatApi(_ *cobra.Command, _ []string) error {
var be errorx.BatchError var be errorx.BatchError
if VarBoolUseStdin { if VarBoolUseStdin {
if err := apiFormatReader(os.Stdin, VarStringDir, VarBoolSkipCheckDeclare); err != nil { if env.UseExperimental() {
be.Add(err) data, err := io.ReadAll(os.Stdin)
if err != nil {
be.Add(err)
} else {
if err := apiF.Source(data, os.Stdout); err != nil {
be.Add(err)
}
}
} else {
if err := apiFormatReader(os.Stdin, VarStringDir, VarBoolSkipCheckDeclare); err != nil {
be.Add(err)
}
} }
} else { } else {
if len(VarStringDir) == 0 { if len(VarStringDir) == 0 {

View File

@@ -28,7 +28,7 @@
"dir": "{{.goctl.api.dir}}", "dir": "{{.goctl.api.dir}}",
"iu": "Ignore update", "iu": "Ignore update",
"stdin": "Use stdin to input api doc content, press \"ctrl + d\" to send EOF", "stdin": "Use stdin to input api doc content, press \"ctrl + d\" to send EOF",
"declare": "Use to skip check api types already declare" "declare": "Use to skip check api types already declare, deprecated if goctl version >= 1.8.3"
}, },
"go": { "go": {
"short": "Generate go files for provided api in api file", "short": "Generate go files for provided api in api file",