Skip to content

Commit

Permalink
Revert "Print the package that was created" (#403)
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 authored Sep 17, 2024
1 parent 25f5cf4 commit 3ed4937
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 53 deletions.
28 changes: 9 additions & 19 deletions pkg/cmd/package/nuget/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewCmdCreate(f factory.Factory) *cobra.Command {
NuPkgCreateFlags: createFlags,
PackageCreateOptions: pack.NewPackageCreateOptions(f, packFlags, cmd),
}
return createRun(cmd, opts)
return createRun(opts)
},
}

Expand All @@ -88,11 +88,7 @@ func NewCmdCreate(f factory.Factory) *cobra.Command {
return cmd
}

func createRun(cmd *cobra.Command, opts *NuPkgCreateOptions) error {
outputFormat, err := cmd.Flags().GetString(constants.FlagOutputFormat)
if err != nil { // should never happen, but fallback if it does
outputFormat = constants.OutputFormatTable
}
func createRun(opts *NuPkgCreateOptions) error {
if !opts.NoPrompt {
if err := pack.PackageCreatePromptMissing(opts.PackageCreateOptions); err != nil {
return err
Expand All @@ -106,7 +102,7 @@ func createRun(cmd *cobra.Command, opts *NuPkgCreateOptions) error {
return errors.New("must supply a package ID")
}

err = applyDefaultsToUnspecifiedPackageOptions(opts)
err := applyDefaultsToUnspecifiedPackageOptions(opts)
if err != nil {
return err
}
Expand All @@ -131,6 +127,11 @@ func createRun(cmd *cobra.Command, opts *NuPkgCreateOptions) error {
pack.VerboseOut(opts.Writer, opts.Verbose.Value, "Packing \"%s\" version \"%s\"...\n", opts.Id.Value, opts.Version.Value)
outFilePath := pack.BuildOutFileName("nupkg", opts.Id.Value, opts.Version.Value)

err = pack.BuildPackage(opts.PackageCreateOptions, outFilePath)
if err != nil {
return err
}

if !opts.NoPrompt {
autoCmd := flag.GenerateAutomationCmd(
opts.CmdPath,
Expand All @@ -150,18 +151,7 @@ func createRun(cmd *cobra.Command, opts *NuPkgCreateOptions) error {
fmt.Fprintf(opts.Writer, "\nAutomation Command: %s\n", autoCmd)
}

nuget, err := pack.BuildPackage(opts.PackageCreateOptions, outFilePath)
if (nuget != nil) {
switch outputFormat {
case constants.OutputFormatBasic:
cmd.Printf("%s\n", nuget.Name())
case constants.OutputFormatJson:
cmd.Printf(`{"Path": "%s"}`, nuget.Name())
default: // table
cmd.Printf("Successfully created package %s\n", nuget.Name())
}
}
return err
return nil
}

func PromptMissing(opts *NuPkgCreateOptions) error {
Expand Down
28 changes: 14 additions & 14 deletions pkg/cmd/package/support/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,37 +165,37 @@ func BuildOutFileName(packageType, id, version string) string {
return fmt.Sprintf("%s.%s.%s", id, version, packageType)
}

func BuildPackage(opts *PackageCreateOptions, outFileName string) (*os.File, error) {
func BuildPackage(opts *PackageCreateOptions, outFileName string) error {
outFilePath := filepath.Join(opts.OutFolder.Value, outFileName)
outPath, err := filepath.Abs(opts.OutFolder.Value)
if err != nil {
return nil, err
return err
}

_, err = os.Stat(outFilePath)
if !opts.Overwrite.Value && err == nil {
return nil, fmt.Errorf("package with name '%s' already exists ...aborting", outFileName)
return fmt.Errorf("package with name '%s' already exists ...aborting", outFileName)
}

VerboseOut(opts.Writer, opts.Verbose.Value, "Saving \"%s\" to \"%s\"...\nAdding files from \"%s\" matching pattern/s \"%s\"\n", outPath, outFileName, outPath, strings.Join(opts.Include.Value, ", "))

filePaths, err := getDistinctPatternMatches(opts.BasePath.Value, opts.Include.Value)
if err != nil {
return nil, err
return err
}

if len(filePaths) == 0 {
return nil, errors.New("no files identified to package")
return errors.New("no files identified to package")
}

return buildArchive(opts.Writer, outFilePath, opts.BasePath.Value, filePaths, opts.Verbose.Value)
}

func buildArchive(out io.Writer, outFilePath string, basePath string, filesToArchive []string, isVerbose bool) (*os.File, error) {
func buildArchive(out io.Writer, outFilePath string, basePath string, filesToArchive []string, isVerbose bool) error {
_, outFile := filepath.Split(outFilePath)
zipFile, err := os.Create(outFilePath)
if err != nil {
return nil, err
return err
}
defer zipFile.Close()

Expand All @@ -210,12 +210,12 @@ func buildArchive(out io.Writer, outFilePath string, basePath string, filesToArc
fullPath := filepath.Join(basePath, path)
fileInfo, err := os.Stat(fullPath)
if err != nil {
return nil, err
return err
}

header, err := zip.FileInfoHeader(fileInfo)
if err != nil {
return nil, err
return err
}

header.Method = zip.Deflate
Expand All @@ -226,7 +226,7 @@ func buildArchive(out io.Writer, outFilePath string, basePath string, filesToArc

headerWriter, err := writer.CreateHeader(header)
if err != nil {
return nil, err
return err
}

if fileInfo.IsDir() {
Expand All @@ -235,23 +235,23 @@ func buildArchive(out io.Writer, outFilePath string, basePath string, filesToArc

f, err := os.Open(fullPath)
if err != nil {
return nil, err
return err
}

_, err = io.Copy(headerWriter, f)
if err == nil {
VerboseOut(out, isVerbose, "Added file: %s\n", path)
} else {
return nil, err
return err
}

err = f.Close()
if err != nil {
return nil, err
return err
}
}

return zipFile, nil
return nil
}

func getDistinctPatternMatches(basePath string, patterns []string) ([]string, error) {
Expand Down
23 changes: 3 additions & 20 deletions pkg/cmd/package/zip/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewCmdCreate(f factory.Factory) *cobra.Command {
`, constants.ExecutableName),
RunE: func(cmd *cobra.Command, args []string) error {
opts := pack.NewPackageCreateOptions(f, createFlags, cmd)
return createRun(cmd, opts)
return createRun(opts)
},
}

Expand All @@ -42,12 +42,7 @@ func NewCmdCreate(f factory.Factory) *cobra.Command {
return cmd
}

func createRun(cmd *cobra.Command, opts *pack.PackageCreateOptions) error {
outputFormat, err := cmd.Flags().GetString(constants.FlagOutputFormat)
if err != nil { // should never happen, but fallback if it does
outputFormat = constants.OutputFormatTable
}

func createRun(opts *pack.PackageCreateOptions) error {
if !opts.NoPrompt {
if err := pack.PackageCreatePromptMissing(opts); err != nil {
return err
Expand Down Expand Up @@ -76,19 +71,7 @@ func createRun(cmd *cobra.Command, opts *pack.PackageCreateOptions) error {
}

outFilePath := pack.BuildOutFileName("zip", opts.Id.Value, opts.Version.Value)

zip, err := pack.BuildPackage(opts, outFilePath)
if (zip != nil) {
switch outputFormat {
case constants.OutputFormatBasic:
cmd.Printf("%s\n", zip.Name())
case constants.OutputFormatJson:
cmd.Printf(`{"Path": "%s"}`, zip.Name())
default: // table
cmd.Printf("Successfully created package %s\n", zip.Name())
}
}
return err
return pack.BuildPackage(opts, outFilePath)
}

func applyDefaultsToUnspecifiedOptions(opts *pack.PackageCreateOptions) {
Expand Down

0 comments on commit 3ed4937

Please sign in to comment.