(cmd *cobra.Command, f factory.Factory, flags *UploadFlags)
| 114 | } |
| 115 | |
| 116 | func uploadRun(cmd *cobra.Command, f factory.Factory, flags *UploadFlags) error { |
| 117 | outputFormat, err := cmd.Flags().GetString(constants.FlagOutputFormat) |
| 118 | if err != nil { // should never happen, but fallback if it does |
| 119 | outputFormat = constants.OutputFormatTable |
| 120 | } |
| 121 | |
| 122 | // package upload doesn't have interactive mode, so we don't care about the question.asker |
| 123 | octopus, err := f.GetSpacedClient(apiclient.NewRequester(cmd)) |
| 124 | if err != nil { |
| 125 | return err |
| 126 | } |
| 127 | // core infrastructure will ask the user for a space interactively, should it need to |
| 128 | space := f.GetCurrentSpace() |
| 129 | if space == nil { |
| 130 | return errors.New("package upload must run with a configured space") |
| 131 | } |
| 132 | |
| 133 | continueOnError := flags.ContinueOnError.Value |
| 134 | |
| 135 | overwriteMode := flags.OverwriteMode.Value |
| 136 | resolvedOverwriteMode := packages.OverwriteMode("") |
| 137 | switch strings.ToLower(overwriteMode) { |
| 138 | case "fail", "failifexists", "": // include aliases from old CLI, default (empty string) = fail |
| 139 | resolvedOverwriteMode = packages.OverwriteModeFailIfExists |
| 140 | case "ignore", "ignoreifexists": |
| 141 | resolvedOverwriteMode = packages.OverwriteModeIgnoreIfExists |
| 142 | case "overwrite", "overwriteexisting", "replace": |
| 143 | resolvedOverwriteMode = packages.OverwriteModeOverwriteExisting |
| 144 | default: |
| 145 | return fmt.Errorf("invalid value '%s' for --overwrite-mode. Valid values are 'fail', 'ignore', 'overwrite'", overwriteMode) |
| 146 | } |
| 147 | |
| 148 | useDeltaCompression := flags.UseDeltaCompression.Value |
| 149 | |
| 150 | var jsonResult uploadViewModel |
| 151 | didErrorsOccur := false |
| 152 | |
| 153 | // with globs it's easy to specify the same thing twice by accident, so keep track of what's been uploaded as we go |
| 154 | seenPackages := make(map[string]bool) |
| 155 | doUpload := func(path string) error { |
| 156 | if !seenPackages[path] { |
| 157 | uploadResult, err := uploadFileAtPath(octopus, space, path, resolvedOverwriteMode, useDeltaCompression, cmd) |
| 158 | |
| 159 | seenPackages[path] = true // whether a given package succeeds or fails, we still don't want to process it twice |
| 160 | |
| 161 | if err != nil { |
| 162 | didErrorsOccur = true // for process exit code |
| 163 | switch outputFormat { |
| 164 | case constants.OutputFormatJson: |
| 165 | jsonResult.Failed = append(jsonResult.Failed, uploadFailedViewModel{ |
| 166 | PackagePath: path, |
| 167 | Error: err.Error(), |
| 168 | }) |
| 169 | case constants.OutputFormatBasic: |
| 170 | cmd.PrintErrf("Failed %s\n", path) |
| 171 | default: |
| 172 | cmd.PrintErrf("Failed to upload package %s - %v\n", path, err) |
| 173 | } |
no test coverage detected