feat: add swag command
This commit is contained in:
20
cmd/swag.go
Normal file
20
cmd/swag.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
func CommandSwag(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "swag",
|
||||
Short: "Generate swag docs",
|
||||
}
|
||||
cmds := []func(*cobra.Command){
|
||||
CommandSwagInit,
|
||||
CommandSwagFmt,
|
||||
}
|
||||
|
||||
for _, c := range cmds {
|
||||
c(cmd)
|
||||
}
|
||||
|
||||
root.AddCommand(cmd)
|
||||
}
|
||||
25
cmd/swag_fmt.go
Normal file
25
cmd/swag_fmt.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/swaggo/swag/format"
|
||||
)
|
||||
|
||||
func CommandSwagFmt(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "fmt",
|
||||
Aliases: []string{"f"},
|
||||
Short: "swag format",
|
||||
RunE: commandSwagFmtE,
|
||||
}
|
||||
|
||||
root.AddCommand(cmd)
|
||||
}
|
||||
|
||||
func commandSwagFmtE(cmd *cobra.Command, args []string) error {
|
||||
return format.New().Build(&format.Config{
|
||||
SearchDir: "./app/http",
|
||||
Excludes: "",
|
||||
MainFile: "main.go",
|
||||
})
|
||||
}
|
||||
54
cmd/swag_init.go
Normal file
54
cmd/swag_init.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/swaggo/swag"
|
||||
"github.com/swaggo/swag/gen"
|
||||
)
|
||||
|
||||
func CommandSwagInit(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "init",
|
||||
Short: "swag init",
|
||||
Aliases: []string{"i"},
|
||||
RunE: commandSwagInitE,
|
||||
}
|
||||
|
||||
root.AddCommand(cmd)
|
||||
}
|
||||
|
||||
func commandSwagInitE(cmd *cobra.Command, args []string) error {
|
||||
leftDelim, rightDelim := "{{", "}}"
|
||||
|
||||
return gen.New().Build(&gen.Config{
|
||||
SearchDir: "./",
|
||||
Excludes: "",
|
||||
ParseExtension: "",
|
||||
MainAPIFile: "main.go",
|
||||
PropNamingStrategy: swag.CamelCase,
|
||||
OutputDir: "./docs",
|
||||
OutputTypes: []string{"go", "json", "yaml"},
|
||||
ParseVendor: false,
|
||||
ParseDependency: 0,
|
||||
MarkdownFilesDir: "",
|
||||
ParseInternal: false,
|
||||
Strict: false,
|
||||
GeneratedTime: false,
|
||||
RequiredByDefault: false,
|
||||
CodeExampleFilesDir: "",
|
||||
ParseDepth: 100,
|
||||
InstanceName: "",
|
||||
OverridesFile: ".swaggo",
|
||||
ParseGoList: true,
|
||||
Tags: "",
|
||||
LeftTemplateDelim: leftDelim,
|
||||
RightTemplateDelim: rightDelim,
|
||||
PackageName: "",
|
||||
Debugger: log.WithField("module", "swag.init"),
|
||||
CollectionFormat: "csv",
|
||||
PackagePrefix: "",
|
||||
State: "",
|
||||
ParseFuncBody: false,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user