@@ -16,71 +16,89 @@ type gateDefinition struct {
1616 newStep func (m * Model ) Step
1717}
1818
19- var gateDefinitions = defaultGateDefinitions ()
20-
21- func gateDef (newStep func (m * Model ) Step , opts ... func (* gateDefinition )) gateDefinition {
22- def := gateDefinition {
23- newStep : newStep ,
24- }
25- for _ , opt := range opts {
26- opt (& def )
27- }
28- return def
29- }
30-
31- func (m * Model ) definitionForGate (gate Gate ) gateDefinition {
32- if def , ok := gateDefinitions [gate ]; ok {
33- return def
19+ func (m * Model ) newStepForGate (gate Gate ) Step {
20+ switch gate {
21+ case GatePreflight :
22+ return preflight .New (m .ctx , m .theme , m .services , m .auth , m .userPrefs , m .orgPrefs , m .scope )
23+ case GateAuthenticate :
24+ return auth .NewAuthenticate (m .ctx , m .theme , m .auth , m .scope )
25+ case GateRoleSelect :
26+ return role .New (m .theme , m .userPrefs , m .scope )
27+ case GateOrgSelect :
28+ return organizations .NewSelect (m .ctx , m .theme , m .services , m .userPrefs , m .auth , m .scope )
29+ case GateOrgCreate :
30+ return organizations .NewCreate (m .ctx , m .theme , m .services , m .userPrefs , m .scope )
31+ case GateAccountSelect :
32+ return accounts .NewSelect (m .ctx , m .theme , * m .state .Org , m .services , m .orgPrefs , m .scope )
33+ case GateAccountCreate :
34+ return accounts .NewCreate (m .ctx , m .theme , * m .state .Org , m .services , m .orgPrefs , m .scope )
35+ case GateRuntimeInit :
36+ return runtimeinit .New (m .theme , * m .state .Org , * m .state .Account , m .scope )
37+ case GateDatadogCheck :
38+ return datadog .NewCheck (m .ctx , m .theme , * m .state .Account , m .services , m .scope )
39+ case GateDatadogRegion :
40+ return datadog .NewRegion (m .theme , m .scope )
41+ case GateDatadogAPIKey :
42+ return datadog .NewAPIKey (m .ctx , m .theme , * m .state .Account , m .state .DDSite , m .services , m .scope )
43+ case GateDatadogAppKey :
44+ return datadog .NewAppKey (m .ctx , m .theme , * m .state .Account , m .state .DDSite , m .state .DDAPIKey , m .services , m .scope )
45+ case GateDatadogDiscovery :
46+ return datadog .NewDiscovery (m .ctx , m .theme , m .state .DDAccount , m .services , m .scope )
47+ case GateWorkspaceSelect :
48+ return workspaces .NewSelect (m .ctx , m .theme , * m .state .Account , m .services , m .orgPrefs , m .scope )
49+ case GateSync :
50+ return sync .New (m .theme , m .syncer , m .scope )
51+ default :
52+ panic ("unsupported onboarding gate: " + gate .String ())
3453 }
35- panic ("unsupported onboarding gate: " + gate .String ())
3654}
3755
3856func defaultGateDefinitions () map [Gate ]gateDefinition {
3957 return map [Gate ]gateDefinition {
40- GatePreflight : gateDef ( func (m * Model ) Step {
58+ GatePreflight : { newStep : func (m * Model ) Step {
4159 return preflight .New (m .ctx , m .theme , m .services , m .auth , m .userPrefs , m .orgPrefs , m .scope )
42- }) ,
43- GateAuthenticate : gateDef ( func (m * Model ) Step {
60+ }} ,
61+ GateAuthenticate : { newStep : func (m * Model ) Step {
4462 return auth .NewAuthenticate (m .ctx , m .theme , m .auth , m .scope )
45- }) ,
46- GateRoleSelect : gateDef ( func (m * Model ) Step {
63+ }} ,
64+ GateRoleSelect : { newStep : func (m * Model ) Step {
4765 return role .New (m .theme , m .userPrefs , m .scope )
48- }) ,
49- GateOrgSelect : gateDef ( func (m * Model ) Step {
66+ }} ,
67+ GateOrgSelect : { newStep : func (m * Model ) Step {
5068 return organizations .NewSelect (m .ctx , m .theme , m .services , m .userPrefs , m .auth , m .scope )
51- }) ,
52- GateOrgCreate : gateDef ( func (m * Model ) Step {
69+ }} ,
70+ GateOrgCreate : { newStep : func (m * Model ) Step {
5371 return organizations .NewCreate (m .ctx , m .theme , m .services , m .userPrefs , m .scope )
54- }) ,
55- GateAccountSelect : gateDef ( func (m * Model ) Step {
72+ }} ,
73+ GateAccountSelect : { newStep : func (m * Model ) Step {
5674 return accounts .NewSelect (m .ctx , m .theme , * m .state .Org , m .services , m .orgPrefs , m .scope )
57- }) ,
58- GateAccountCreate : gateDef ( func (m * Model ) Step {
75+ }} ,
76+ GateAccountCreate : { newStep : func (m * Model ) Step {
5977 return accounts .NewCreate (m .ctx , m .theme , * m .state .Org , m .services , m .orgPrefs , m .scope )
60- }) ,
61- GateRuntimeInit : gateDef ( func (m * Model ) Step {
78+ }} ,
79+ GateRuntimeInit : { newStep : func (m * Model ) Step {
6280 return runtimeinit .New (m .theme , * m .state .Org , * m .state .Account , m .scope )
63- }) ,
64- GateDatadogCheck : gateDef ( func (m * Model ) Step {
81+ }} ,
82+ GateDatadogCheck : { newStep : func (m * Model ) Step {
6583 return datadog .NewCheck (m .ctx , m .theme , * m .state .Account , m .services , m .scope )
66- }) ,
67- GateDatadogRegion : gateDef ( func (m * Model ) Step {
84+ }} ,
85+ GateDatadogRegion : { newStep : func (m * Model ) Step {
6886 return datadog .NewRegion (m .theme , m .scope )
69- }) ,
70- GateDatadogAPIKey : gateDef ( func (m * Model ) Step {
87+ }} ,
88+ GateDatadogAPIKey : { newStep : func (m * Model ) Step {
7189 return datadog .NewAPIKey (m .ctx , m .theme , * m .state .Account , m .state .DDSite , m .services , m .scope )
72- }) ,
73- GateDatadogAppKey : gateDef ( func (m * Model ) Step {
90+ }} ,
91+ GateDatadogAppKey : { newStep : func (m * Model ) Step {
7492 return datadog .NewAppKey (m .ctx , m .theme , * m .state .Account , m .state .DDSite , m .state .DDAPIKey , m .services , m .scope )
75- }) ,
76- GateDatadogDiscovery : gateDef ( func (m * Model ) Step {
93+ }} ,
94+ GateDatadogDiscovery : { newStep : func (m * Model ) Step {
7795 return datadog .NewDiscovery (m .ctx , m .theme , m .state .DDAccount , m .services , m .scope )
78- }) ,
79- GateWorkspaceSelect : gateDef ( func (m * Model ) Step {
96+ }} ,
97+ GateWorkspaceSelect : { newStep : func (m * Model ) Step {
8098 return workspaces .NewSelect (m .ctx , m .theme , * m .state .Account , m .services , m .orgPrefs , m .scope )
81- }) ,
82- GateSync : gateDef ( func (m * Model ) Step {
99+ }} ,
100+ GateSync : { newStep : func (m * Model ) Step {
83101 return sync .New (m .theme , m .syncer , m .scope )
84- }) ,
102+ }} ,
85103 }
86104}
0 commit comments