@@ -2,11 +2,9 @@ package lifecycle
2
2
3
3
import (
4
4
"errors"
5
- "fmt"
6
5
commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
7
6
"github.com/jfrog/jfrog-cli-core/v2/common/commands"
8
7
"github.com/jfrog/jfrog-cli-core/v2/common/spec"
9
- speccore "github.com/jfrog/jfrog-cli-core/v2/common/spec"
10
8
coreCommon "github.com/jfrog/jfrog-cli-core/v2/docs/common"
11
9
"github.com/jfrog/jfrog-cli-core/v2/lifecycle"
12
10
coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -26,7 +24,6 @@ import (
26
24
"github.com/jfrog/jfrog-client-go/utils"
27
25
"github.com/jfrog/jfrog-client-go/utils/errorutils"
28
26
"github.com/urfave/cli"
29
- "os"
30
27
"strings"
31
28
)
32
29
@@ -134,56 +131,21 @@ func validateCreateReleaseBundleContext(c *cli.Context) error {
134
131
}
135
132
136
133
func assertValidCreationMethod (c * cli.Context ) error {
137
- // Determine the methods provided
138
134
methods := []bool {
139
- c .IsSet ("spec" ),
140
- c .IsSet (cliutils .Builds ),
141
- c .IsSet (cliutils .ReleaseBundles ),
142
- }
143
- methodCount := coreutils .SumTrueValues (methods )
144
-
145
- // Validate that only one creation method is provided
146
- if err := validateSingleCreationMethod (methodCount ); err != nil {
147
- return err
148
- }
149
-
150
- if err := validateCreationValuesPresence (c , methodCount ); err != nil {
151
- return err
152
- }
153
- return nil
154
- }
155
-
156
- func validateSingleCreationMethod (methodCount int ) error {
157
- if methodCount > 1 {
158
- return errorutils .CheckErrorf (
159
- "exactly one creation source must be supplied: --%s, --%s, or --%s.\n " +
160
- "Opt to use the --%s option as the --%s and --%s are deprecated" ,
161
- "spec" , cliutils .Builds , cliutils .ReleaseBundles ,
135
+ c .IsSet ("spec" ), c .IsSet (cliutils .Builds ), c .IsSet (cliutils .ReleaseBundles )}
136
+ if coreutils .SumTrueValues (methods ) > 1 {
137
+ return errorutils .CheckErrorf ("exactly one creation source must be supplied: --%s, --%s or --%s.\n " +
138
+ "Opt to use the --%s option as the --%s and --%s are deprecated" ,
162
139
"spec" , cliutils .Builds , cliutils .ReleaseBundles ,
163
- )
140
+ "spec" , cliutils . Builds , cliutils . ReleaseBundles )
164
141
}
165
- return nil
166
- }
167
-
168
- func validateCreationValuesPresence (c * cli.Context , methodCount int ) error {
169
- if methodCount == 0 {
170
- if ! areBuildFlagsSet (c ) && ! areBuildEnvVarsSet () {
171
- return errorutils .CheckErrorf ("Either --build-name or JFROG_CLI_BUILD_NAME, and --build-number or JFROG_CLI_BUILD_NUMBER must be defined" )
172
- }
142
+ // If the user did not provide a source, we suggest only the recommended spec approach.
143
+ if coreutils .SumTrueValues (methods ) == 0 {
144
+ return errorutils .CheckErrorf ("the --spec option is mandatory" )
173
145
}
174
146
return nil
175
147
}
176
148
177
- // areBuildFlagsSet checks if build-name or build-number flags are set.
178
- func areBuildFlagsSet (c * cli.Context ) bool {
179
- return c .IsSet (cliutils .BuildName ) || c .IsSet (cliutils .BuildNumber )
180
- }
181
-
182
- // areBuildEnvVarsSet checks if build environment variables are set.
183
- func areBuildEnvVarsSet () bool {
184
- return os .Getenv ("JFROG_CLI_BUILD_NUMBER" ) != "" && os .Getenv ("JFROG_CLI_BUILD_NAME" ) != ""
185
- }
186
-
187
149
func create (c * cli.Context ) (err error ) {
188
150
if err = validateCreateReleaseBundleContext (c ); err != nil {
189
151
return err
@@ -207,34 +169,10 @@ func create(c *cli.Context) (err error) {
207
169
}
208
170
209
171
func getReleaseBundleCreationSpec (c * cli.Context ) (* spec.SpecFiles , error ) {
210
- // לֹhecking if the "builds" or "release-bundles" flags are set - if so, the spec flag should be ignored
211
- if c .IsSet (cliutils .Builds ) || c .IsSet (cliutils .ReleaseBundles ) {
212
- return nil , nil
213
- }
214
-
215
- // Check if the "spec" flag is set - if so, return the spec
216
172
if c .IsSet ("spec" ) {
217
173
return cliutils .GetSpec (c , true , false )
218
174
}
219
-
220
- // Else - create a spec from the buildName and buildnumber flags or env vars
221
- buildName := getStringFlagOrEnv (c , cliutils .BuildName , coreutils .BuildName )
222
- buildNumber := getStringFlagOrEnv (c , cliutils .BuildNumber , coreutils .BuildNumber )
223
-
224
- if buildName != "" && buildNumber != "" {
225
- return speccore .CreateSpecFromBuildNameAndNumber (buildName , buildNumber )
226
- }
227
-
228
- return nil , fmt .Errorf ("either the --spec flag must be provided, " +
229
- "or both --build-name and --build-number flags (or their corresponding environment variables " +
230
- "JFROG_CLI_BUILD_NAME and JFROG_CLI_BUILD_NUMBER) must be set" )
231
- }
232
-
233
- func getStringFlagOrEnv (c * cli.Context , flag string , envVar string ) string {
234
- if c .IsSet (flag ) {
235
- return c .String (flag )
236
- }
237
- return os .Getenv (envVar )
175
+ return nil , nil
238
176
}
239
177
240
178
func promote (c * cli.Context ) error {
0 commit comments