From 3ed49375b568365333b36e59b0e71e3fc4d8168f Mon Sep 17 00:00:00 2001 From: domenicsim1 <87625140+domenicsim1@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:03:01 +1000 Subject: [PATCH] Revert "Print the package that was created" (#403) --- pkg/cmd/package/nuget/create/create.go | 28 +++++++++----------------- pkg/cmd/package/support/pack.go | 28 +++++++++++++------------- pkg/cmd/package/zip/create/create.go | 23 +++------------------ 3 files changed, 26 insertions(+), 53 deletions(-) diff --git a/pkg/cmd/package/nuget/create/create.go b/pkg/cmd/package/nuget/create/create.go index dd466cb3..599b56da 100644 --- a/pkg/cmd/package/nuget/create/create.go +++ b/pkg/cmd/package/nuget/create/create.go @@ -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) }, } @@ -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 @@ -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 } @@ -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, @@ -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 { diff --git a/pkg/cmd/package/support/pack.go b/pkg/cmd/package/support/pack.go index 588d2402..cd323b38 100644 --- a/pkg/cmd/package/support/pack.go +++ b/pkg/cmd/package/support/pack.go @@ -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() @@ -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 @@ -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() { @@ -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) { diff --git a/pkg/cmd/package/zip/create/create.go b/pkg/cmd/package/zip/create/create.go index 21c7be04..afd8bf85 100644 --- a/pkg/cmd/package/zip/create/create.go +++ b/pkg/cmd/package/zip/create/create.go @@ -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) }, } @@ -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 @@ -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) {