Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions command/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,26 @@ var ScratchSettingIds = map[ScratchSetting][]string{
PermsetsInFieldCreation: {"permsetsInFieldCreation"},
}

type ScratchRelease enumflag.Flag

const (
ReleaseDefault ScratchRelease = iota
ReleasePreview
ReleasePrevious
)

var ScratchReleaseIds = map[ScratchRelease][]string{
ReleaseDefault: {""},
ReleasePreview: {"preview"},
ReleasePrevious: {"previous"},
}

var (
selectedFeatures []ScratchFeature
selectedProducts []ScratchProduct
selectedEdition ScratchEdition
selectedSettings []ScratchSetting
selectedRelease ScratchRelease
featureQuantities map[string]string
)

Expand Down Expand Up @@ -142,6 +157,10 @@ logged in system. non-production server to login to (values are 'pre',
enumflag.NewSlice(&selectedSettings, "setting", ScratchSettingIds, enumflag.EnumCaseInsensitive),
"setting",
"setting to enable (can be specified multiple times); see command help for available settings")
scratchCmd.Flags().Var(
enumflag.New(&selectedRelease, "release", ScratchReleaseIds, enumflag.EnumCaseInsensitive),
"release",
"Salesforce release for scratch org: preview (next release) or previous")

loginCmd.AddCommand(scratchCmd)
RootCmd.AddCommand(loginCmd)
Expand Down Expand Up @@ -185,6 +204,10 @@ Available Settings (deployed after org creation):
enableApexApprovalLockUnlock - Allow Apex to lock/unlock approval processes
permsetsInFieldCreation - Allow assigning permission sets during field creation

Available Releases:
preview - Create scratch org on the next (preview) release
previous - Create scratch org on the previous release

Examples:
force login scratch --product fsc
force login scratch --feature PersonAccounts --feature StateAndCountryPicklist
Expand All @@ -194,15 +217,18 @@ Examples:
force login scratch --setting enableEnhancedNotes
force login scratch --setting enableQuote
force login scratch --product communities
force login scratch --product healthcloud`,
force login scratch --product healthcloud
force login scratch --release preview
force login scratch --release previous`,
Run: func(cmd *cobra.Command, args []string) {
scratchUser, _ := cmd.Flags().GetString("username")
scratchNamespace, _ := cmd.Flags().GetString("namespace")
quantities, _ := cmd.Flags().GetStringToString("quantity")
allFeatures := expandProductsToFeatures(selectedProducts, selectedFeatures, quantities)
edition := ScratchEditionIds[selectedEdition][0]
allSettings := expandProductsToSettings(selectedProducts, selectedSettings)
scratchLogin(scratchUser, allFeatures, edition, allSettings, scratchNamespace)
release := ScratchReleaseIds[selectedRelease][0]
scratchLogin(scratchUser, allFeatures, edition, allSettings, scratchNamespace, release)
},
}

Expand Down Expand Up @@ -329,8 +355,8 @@ func expandProductsToSettings(products []ScratchProduct, settings []ScratchSetti
return uniqueSettings
}

func scratchLogin(scratchUser string, features []string, edition string, settings []string, namespace string) {
_, err := ForceScratchCreateLoginAndSaveWithNamespace(scratchUser, features, edition, settings, namespace, os.Stderr)
func scratchLogin(scratchUser string, features []string, edition string, settings []string, namespace string, release string) {
_, err := ForceScratchCreateLoginAndSaveWithRelease(scratchUser, features, edition, settings, namespace, release, os.Stderr)
if err != nil {
ErrorAndExit(err.Error())
}
Expand Down
48 changes: 48 additions & 0 deletions command/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,3 +369,51 @@ func TestScratchCommandHasNamespaceFlag(t *testing.T) {
t.Fatal("Flag namespace not found")
}
}

func TestScratchCommandHasReleaseFlag(t *testing.T) {
flag := scratchCmd.Flags().Lookup("release")
if flag == nil {
t.Fatal("Flag release not found")
}
}

func TestScratchReleaseIds_AllReleasesDefined(t *testing.T) {
expectedReleases := map[string]bool{
"": true,
"preview": true,
"previous": true,
}

if len(ScratchReleaseIds) != len(expectedReleases) {
t.Errorf("Expected %d releases, got %d", len(expectedReleases), len(ScratchReleaseIds))
}

for _, ids := range ScratchReleaseIds {
if len(ids) != 1 {
t.Errorf("Expected 1 ID per release, got %d", len(ids))
continue
}
releaseName := ids[0]
if !expectedReleases[releaseName] {
t.Errorf("Unexpected release: %s", releaseName)
}
}
}

func TestScratchReleaseIds_Preview(t *testing.T) {
if ScratchReleaseIds[ReleasePreview][0] != "preview" {
t.Errorf("Expected 'preview' for ReleasePreview, got %s", ScratchReleaseIds[ReleasePreview][0])
}
}

func TestScratchReleaseIds_Previous(t *testing.T) {
if ScratchReleaseIds[ReleasePrevious][0] != "previous" {
t.Errorf("Expected 'previous' for ReleasePrevious, got %s", ScratchReleaseIds[ReleasePrevious][0])
}
}

func TestScratchReleaseIds_Default(t *testing.T) {
if ScratchReleaseIds[ReleaseDefault][0] != "" {
t.Errorf("Expected empty string for ReleaseDefault, got %s", ScratchReleaseIds[ReleaseDefault][0])
}
}
7 changes: 7 additions & 0 deletions docs/force_login_scratch.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ Available Settings (deployed after org creation):
enableApexApprovalLockUnlock - Allow Apex to lock/unlock approval processes
permsetsInFieldCreation - Allow assigning permission sets during field creation

Available Releases:
preview - Create scratch org on the next (preview) release
previous - Create scratch org on the previous release

Examples:
force login scratch --product fsc
force login scratch --feature PersonAccounts --feature StateAndCountryPicklist
Expand All @@ -49,6 +53,8 @@ Examples:
force login scratch --setting enableQuote
force login scratch --product communities
force login scratch --product healthcloud
force login scratch --release preview
force login scratch --release previous

```
force login scratch [flags]
Expand All @@ -63,6 +69,7 @@ force login scratch [flags]
--namespace string namespace for the scratch org
--product product product shortcut for features (can be specified multiple times); see command help for available products (default [])
--quantity stringToString override default quantity for features (e.g., FinancialServicesUser=5); default quantity is 10 (default [])
--release release Salesforce release for scratch org: preview (next release) or previous
--setting setting setting to enable (can be specified multiple times); see command help for available settings (default [])
--username string username for scratch org user
```
Expand Down
6 changes: 5 additions & 1 deletion lib/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,17 @@ func ForceScratchCreateLoginAndSave(scratchUser string, features []string, editi
}

func ForceScratchCreateLoginAndSaveWithNamespace(scratchUser string, features []string, edition string, settings []string, namespace string, output *os.File) (username string, err error) {
return ForceScratchCreateLoginAndSaveWithRelease(scratchUser, features, edition, settings, namespace, "", output)
}

func ForceScratchCreateLoginAndSaveWithRelease(scratchUser string, features []string, edition string, settings []string, namespace string, release string, output *os.File) (username string, err error) {
force, err := ActiveForce()
if err != nil {
err = errors.New("You must be logged into a Dev Hub org to authenticate as a scratch org user.")
return
}
fmt.Fprintln(os.Stderr, "Creating new Scratch Org...")
scratchOrgId, err := force.CreateScratchOrgWithUserFeaturesEditionSettingsAndNamespace(scratchUser, features, edition, settings, namespace)
scratchOrgId, err := force.CreateScratchOrgWithRelease(scratchUser, features, edition, settings, namespace, release)
if err != nil {
return
}
Expand Down
7 changes: 7 additions & 0 deletions lib/scratch.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ func (f *Force) CreateScratchOrgWithUserFeaturesEditionAndSettings(username stri
}

func (f *Force) CreateScratchOrgWithUserFeaturesEditionSettingsAndNamespace(username string, features []string, edition string, settings []string, namespace string) (id string, err error) {
return f.CreateScratchOrgWithRelease(username, features, edition, settings, namespace, "")
}

func (f *Force) CreateScratchOrgWithRelease(username string, features []string, edition string, settings []string, namespace string, release string) (id string, err error) {
params := make(map[string]string)
params["ConnectedAppCallbackUrl"] = "http://localhost:1717/OauthRedirect"
params["ConnectedAppConsumerKey"] = "PlatformCLI"
Expand Down Expand Up @@ -305,6 +309,9 @@ func (f *Force) CreateScratchOrgWithUserFeaturesEditionSettingsAndNamespace(user
if username != "" {
params["Username"] = username
}
if release != "" {
params["Release"] = release
}
id, err, messages := f.CreateRecord("ScratchOrgInfo", params)
if err != nil {
if len(messages) == 1 && messages[0].ErrorCode == "NOT_FOUND" {
Expand Down
Loading