(cmd *cobra.Command, opts *pack.PackageCreateOptions)
| 43 | } |
| 44 | |
| 45 | func createRun(cmd *cobra.Command, opts *pack.PackageCreateOptions) error { |
| 46 | outputFormat, err := cmd.Flags().GetString(constants.FlagOutputFormat) |
| 47 | if err != nil { // should never happen, but fallback if it does |
| 48 | outputFormat = constants.OutputFormatTable |
| 49 | } |
| 50 | |
| 51 | if !opts.NoPrompt { |
| 52 | if err := pack.PackageCreatePromptMissing(opts); err != nil { |
| 53 | return err |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | if opts.Id.Value == "" { |
| 58 | return errors.New("must supply a package ID") |
| 59 | } |
| 60 | applyDefaultsToUnspecifiedOptions(opts) |
| 61 | |
| 62 | pack.VerboseOut(opts.Writer, opts.Verbose.Value, "Packing \"%s\" version \"%s\"...\n", opts.Id.Value, opts.Version.Value) |
| 63 | |
| 64 | if !opts.NoPrompt { |
| 65 | autoCmd := flag.GenerateAutomationCmd( |
| 66 | opts.CmdPath, "", |
| 67 | opts.Id, |
| 68 | opts.Version, |
| 69 | opts.BasePath, |
| 70 | opts.OutFolder, |
| 71 | opts.Include, |
| 72 | opts.Verbose, |
| 73 | opts.Overwrite, |
| 74 | ) |
| 75 | fmt.Fprintf(opts.Writer, "\nAutomation Command: %s\n", autoCmd) |
| 76 | } |
| 77 | |
| 78 | outFilePath := pack.BuildOutFileName("zip", opts.Id.Value, opts.Version.Value) |
| 79 | |
| 80 | zip, err := pack.BuildPackage(opts, outFilePath) |
| 81 | if zip != nil { |
| 82 | switch outputFormat { |
| 83 | case constants.OutputFormatBasic: |
| 84 | cmd.Printf("%s\n", zip.Name()) |
| 85 | case constants.OutputFormatJson: |
| 86 | cmd.Printf(`{"Path":"%s"}`, zip.Name()) |
| 87 | cmd.Println() |
| 88 | default: // table |
| 89 | cmd.Printf("Successfully created package %s\n", zip.Name()) |
| 90 | } |
| 91 | } |
| 92 | return err |
| 93 | } |
| 94 | |
| 95 | func applyDefaultsToUnspecifiedOptions(opts *pack.PackageCreateOptions) { |
| 96 | if opts.Version.Value == "" { |
no test coverage detected