@@ -2,11 +2,9 @@ package lifecycle
22
33import (
44 "errors"
5- "fmt"
65 commonCliUtils "github.com/jfrog/jfrog-cli-core/v2/common/cliutils"
76 "github.com/jfrog/jfrog-cli-core/v2/common/commands"
87 "github.com/jfrog/jfrog-cli-core/v2/common/spec"
9- speccore "github.com/jfrog/jfrog-cli-core/v2/common/spec"
108 coreCommon "github.com/jfrog/jfrog-cli-core/v2/docs/common"
119 "github.com/jfrog/jfrog-cli-core/v2/lifecycle"
1210 coreConfig "github.com/jfrog/jfrog-cli-core/v2/utils/config"
@@ -26,7 +24,6 @@ import (
2624 "github.com/jfrog/jfrog-client-go/utils"
2725 "github.com/jfrog/jfrog-client-go/utils/errorutils"
2826 "github.com/urfave/cli"
29- "os"
3027 "strings"
3128)
3229
@@ -134,56 +131,21 @@ func validateCreateReleaseBundleContext(c *cli.Context) error {
134131}
135132
136133func assertValidCreationMethod (c * cli.Context ) error {
137- // Determine the methods provided
138134 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" ,
162139 "spec" , cliutils .Builds , cliutils .ReleaseBundles ,
163- )
140+ "spec" , cliutils . Builds , cliutils . ReleaseBundles )
164141 }
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" )
173145 }
174146 return nil
175147}
176148
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-
187149func create (c * cli.Context ) (err error ) {
188150 if err = validateCreateReleaseBundleContext (c ); err != nil {
189151 return err
@@ -207,34 +169,10 @@ func create(c *cli.Context) (err error) {
207169}
208170
209171func 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
216172 if c .IsSet ("spec" ) {
217173 return cliutils .GetSpec (c , true , false )
218174 }
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
238176}
239177
240178func promote (c * cli.Context ) error {
0 commit comments