生成目录并拷贝文件
(src, dest string)
| 115 | |
| 116 | // 生成目录并拷贝文件 |
| 117 | func copyFile(src, dest string) (w int64, err error) { |
| 118 | srcFile, err := os.Open(src) |
| 119 | if err != nil { |
| 120 | fmt.Println(err.Error()) |
| 121 | return |
| 122 | } |
| 123 | defer srcFile.Close() |
| 124 | //分割path目录 |
| 125 | destSplitPathDirs := strings.Split(dest, "/") |
| 126 | //检测时候存在目录 |
| 127 | destSplitPath := "" |
| 128 | for index, dir := range destSplitPathDirs { |
| 129 | if index < len(destSplitPathDirs)-1 { |
| 130 | destSplitPath = destSplitPath + dir + "/" |
| 131 | b := common.IsExist(destSplitPath) |
| 132 | if !b { |
| 133 | //创建目录 |
| 134 | err := os.Mkdir(destSplitPath, os.ModePerm) |
| 135 | if err != nil { |
| 136 | fmt.Println(err) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | dstFile, err := os.Create(dest) |
| 142 | if err != nil { |
| 143 | fmt.Println(err.Error()) |
| 144 | return |
| 145 | } |
| 146 | defer dstFile.Close() |
| 147 | return io.Copy(dstFile, srcFile) |
| 148 | } |
| 149 | |
| 150 | // 从command的参数中获取模板设置信息 |
| 151 | func getTemplateSetting(cmd *cobra.Command, args []string) (*TemplateTypeBo, error) { |