make_request.go 487 B

12345678910111213141516171819202122
  1. package make
  2. import (
  3. "fmt"
  4. "github.com/spf13/cobra"
  5. )
  6. var CmdMakeRequest = &cobra.Command{
  7. Use: "request",
  8. Short: "Create request file, example: make request user",
  9. Run: runMakeRequest,
  10. Args: cobra.ExactArgs(1), // 只允许且必须传 1 个参数
  11. }
  12. func runMakeRequest(cmd *cobra.Command, args []string) {
  13. model := makeModelFromString(args[0])
  14. filePath := fmt.Sprintf("app/requests/%s_request.go", model.PackageName)
  15. createFileFromTpl(filePath, "request", model)
  16. }