| 166 | } |
| 167 | |
| 168 | func BuildPackage(opts *PackageCreateOptions, outFileName string) (*os.File, error) { |
| 169 | outFilePath := filepath.Join(opts.OutFolder.Value, outFileName) |
| 170 | outPath, err := filepath.Abs(opts.OutFolder.Value) |
| 171 | if err != nil { |
| 172 | return nil, err |
| 173 | } |
| 174 | |
| 175 | _, err = os.Stat(outFilePath) |
| 176 | if !opts.Overwrite.Value && err == nil { |
| 177 | return nil, fmt.Errorf("package with name '%s' already exists ...aborting", outFileName) |
| 178 | } |
| 179 | |
| 180 | VerboseOut(opts.Writer, opts.Verbose.Value, "Saving \"%s\" to \"%s\"...\nAdding files from \"%s\" matching pattern/s \"%s\"\n", outFileName, outPath, opts.BasePath.Value, strings.Join(opts.Include.Value, ", ")) |
| 181 | |
| 182 | filePaths, err := getDistinctPatternMatches(opts.BasePath.Value, opts.Include.Value) |
| 183 | if err != nil { |
| 184 | return nil, err |
| 185 | } |
| 186 | |
| 187 | if len(filePaths) == 0 { |
| 188 | return nil, errors.New("no files identified to package") |
| 189 | } |
| 190 | |
| 191 | return buildArchive(opts.Writer, outFilePath, opts.BasePath.Value, filePaths, opts.Verbose.Value) |
| 192 | } |
| 193 | |
| 194 | func buildArchive(out io.Writer, outFilePath string, basePath string, filesToArchive []string, isVerbose bool) (*os.File, error) { |
| 195 | _, outFile := filepath.Split(outFilePath) |