Skip to content

Commit 6237fe6

Browse files
committed
refactor: isolate onboarding core state bridge
1 parent f9a0cb2 commit 6237fe6

2 files changed

Lines changed: 37 additions & 32 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package onboarding
2+
3+
import (
4+
"github.com/usetero/cli/internal/core/bootstrap"
5+
"github.com/usetero/cli/internal/domain"
6+
)
7+
8+
func (m *Model) toCoreState() bootstrap.State {
9+
return bootstrap.State{
10+
User: m.state.user,
11+
Org: m.state.org,
12+
Account: m.state.account,
13+
Workspace: m.state.workspace,
14+
DDSite: m.state.ddSite,
15+
DDAPIKey: m.state.ddAPIKey,
16+
DDAccount: m.state.ddAccount,
17+
}
18+
}
19+
20+
func (m *Model) applyCoreState(state bootstrap.State) {
21+
m.state.user = state.User
22+
m.state.org = state.Org
23+
m.state.account = state.Account
24+
m.state.workspace = state.Workspace
25+
m.state.ddSite = state.DDSite
26+
m.state.ddAPIKey = state.DDAPIKey
27+
m.state.ddAccount = state.DDAccount
28+
m.syncServicesToState()
29+
}
30+
31+
func (m *Model) syncServicesToState() {
32+
accountID := domain.AccountID("")
33+
if m.state.account != nil {
34+
accountID = m.state.account.ID
35+
}
36+
m.services = m.services.WithAccountID(accountID)
37+
}

‎internal/app/onboarding/transition_handlers.go‎

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,8 @@ import (
77

88
"github.com/usetero/cli/internal/app/onboarding/msgs"
99
"github.com/usetero/cli/internal/core/bootstrap"
10-
"github.com/usetero/cli/internal/domain"
1110
)
1211

13-
func (m *Model) toCoreState() bootstrap.State {
14-
return bootstrap.State{
15-
User: m.state.user,
16-
Org: m.state.org,
17-
Account: m.state.account,
18-
Workspace: m.state.workspace,
19-
DDSite: m.state.ddSite,
20-
DDAPIKey: m.state.ddAPIKey,
21-
DDAccount: m.state.ddAccount,
22-
}
23-
}
24-
25-
func (m *Model) applyCoreState(state bootstrap.State) {
26-
m.state.user = state.User
27-
m.state.org = state.Org
28-
m.state.account = state.Account
29-
m.state.workspace = state.Workspace
30-
m.state.ddSite = state.DDSite
31-
m.state.ddAPIKey = state.DDAPIKey
32-
m.state.ddAccount = state.DDAccount
33-
m.syncServicesToState()
34-
}
35-
36-
func (m *Model) syncServicesToState() {
37-
accountID := domain.AccountID("")
38-
if m.state.account != nil {
39-
accountID = m.state.account.ID
40-
}
41-
m.services = m.services.WithAccountID(accountID)
42-
}
43-
4412
func (m *Model) handlePreflightResolved(msg msgs.PreflightResolved) TransitionOutcome {
4513
m.scope.Debug("preflight complete",
4614
slog.String("outcome", string(msg.State.Outcome)),

0 commit comments

Comments
 (0)