MCPcopy
hub / github.com/Azure/aztfexport / Update

Method Update

internal/ui/ui.go:119–202  ·  view source on GitHub ↗
(msg tea.Msg)

Source from the content-addressed store, hash-verified

117}
118
119func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
120 if _, ok := msg.(spinner.TickMsg); !ok {
121 m.meta.Logger().Log(context.Background(), log.LevelTrace, "UI update", "status", m.status, "msg", fmt.Sprintf("%#v", msg))
122 }
123
124 switch msg := msg.(type) {
125 case tea.WindowSizeMsg:
126 m.winsize = msg
127 case tea.KeyMsg:
128 switch msg.Type {
129 case tea.KeyCtrlC:
130 m.status = statusQuitting
131 return m, aztfexportclient.Quit(m.ctx, m.meta)
132 }
133 case spinner.TickMsg:
134 var cmd tea.Cmd
135 m.spinner, cmd = m.spinner.Update(msg)
136 return m, cmd
137 case aztfexportclient.NewClientMsg:
138 m.meta = msg
139 m.status = statusInit
140 return m, aztfexportclient.Init(m.ctx, m.meta)
141 case aztfexportclient.InitProviderDoneMsg:
142 m.status = statusListingResource
143 return m, aztfexportclient.ListResource(m.ctx, m.meta)
144 case aztfexportclient.ListResourceDoneMsg:
145 m.status = statusBuildingImportList
146 m.importlist = importlist.NewModel(m.ctx, m.meta, msg.List, 0)
147 // Trigger a windows resize cmd to resize the importlist model.
148 // Though we can pass the winsize as input variable during model initialization.
149 // But this way we only need to maintain the resizing logic at one place (which takes consideration of the title height).
150 cmd := func() tea.Msg { return m.winsize }
151 return m, cmd
152 case aztfexportclient.ShowImportErrorMsg:
153 m.status = statusImportErrorMsg
154 m.importerrormsg = msg
155 return m, nil
156 case aztfexportclient.StartImportMsg:
157 m.status = statusImporting
158 m.progress = progress.NewModel(m.ctx, m.meta, m.parallelism, msg.List)
159 return m, tea.Batch(
160 m.progress.Init(),
161 // Resize the progress bar
162 func() tea.Msg { return m.winsize },
163 )
164 case aztfexportclient.ImportDoneMsg:
165 for idx, item := range msg.List {
166 if item.ImportError != nil {
167 m.status = statusBuildingImportList
168 m.importlist = importlist.NewModel(m.ctx, m.meta, msg.List, idx)
169 cmd := func() tea.Msg { return m.winsize }
170 return m, cmd
171 }
172 }
173 m.status = statusPushState
174 return m, aztfexportclient.PushState(m.ctx, m.meta, msg.List)
175 case aztfexportclient.PushStateDoneMsg:
176 m.status = statusExportResourceMapping

Callers 1

updateChildrenFunction · 0.45

Calls 14

QuitFunction · 0.92
InitFunction · 0.92
ListResourceFunction · 0.92
NewModelFunction · 0.92
NewModelFunction · 0.92
PushStateFunction · 0.92
ExportResourceMappingFunction · 0.92
ExportSkippedResourcesFunction · 0.92
GenerateCfgFunction · 0.92
CleanUpWorkspaceFunction · 0.92
updateChildrenFunction · 0.85
LoggerMethod · 0.65

Tested by

no test coverage detected