feat: 增加命令行工具的参数支持,包括路径、干运行模式和输出目录选项
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -14,28 +15,35 @@ import (
|
||||
)
|
||||
|
||||
func CommandGenRoute(root *cobra.Command) {
|
||||
cmd := &cobra.Command{
|
||||
Use: "route",
|
||||
Short: "generate routes",
|
||||
RunE: commandGenRouteE,
|
||||
PostRunE: commandGenProviderE,
|
||||
}
|
||||
cmd := &cobra.Command{
|
||||
Use: "route",
|
||||
Short: "generate routes",
|
||||
RunE: commandGenRouteE,
|
||||
PostRunE: commandGenProviderE,
|
||||
}
|
||||
|
||||
root.AddCommand(cmd)
|
||||
cmd.Flags().String("path", ".", "Base path to scan (defaults to CWD)")
|
||||
|
||||
root.AddCommand(cmd)
|
||||
}
|
||||
|
||||
// https://go.ipao.vip/atomctl/pkg/swag?tab=readme-ov-file#api-operation
|
||||
func commandGenRouteE(cmd *cobra.Command, args []string) error {
|
||||
var err error
|
||||
var path string
|
||||
if len(args) > 0 {
|
||||
path = args[0]
|
||||
} else {
|
||||
path, err = os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
var err error
|
||||
var path string
|
||||
if len(args) > 0 {
|
||||
path = args[0]
|
||||
} else {
|
||||
path, err = os.Getwd()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// allow overriding via --path flag
|
||||
if f := cmd.Flag("path"); f != nil && f.Value.String() != "." && f.Value.String() != "" {
|
||||
path = f.Value.String()
|
||||
}
|
||||
|
||||
path, _ = filepath.Abs(path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user