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

Method Update

internal/ui/importlist/importlist.go:112–195  ·  view source on GitHub ↗
(msg tea.Msg)

Source from the content-addressed store, hash-verified

110}
111
112func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
113 var cmd tea.Cmd
114
115 switch msg := msg.(type) {
116 case tea.KeyMsg:
117 // Don't intercept the keys (e.g. "w") when user is inputting.
118 if m.isUserTyping() {
119 break
120 }
121
122 switch {
123 case key.Matches(msg, m.listkeys.apply):
124 // Leave filter applied state before applying the import list
125 if m.list.FilterState() == list.FilterApplied {
126 m.list.ResetFilter()
127 }
128
129 // In case all items are marked as skip, show a warning and do nothing.
130 if m.isNothingToImport() {
131 return m, m.list.NewStatusMessage(common.ErrorMsgStyle.Render("All resources are skipped, nothing to import"))
132 }
133
134 // Ensure all items pass validation
135 if !m.userInputsAreValid() {
136 return m, m.list.NewStatusMessage(common.ErrorMsgStyle.Render("One or more user input is invalid"))
137 }
138
139 return m, aztfexportclient.StartImport(m.importList(true))
140 case key.Matches(msg, m.listkeys.skip):
141 sel := m.list.SelectedItem()
142 if sel == nil {
143 return m, nil
144 }
145 selItem := sel.(Item)
146
147 if !selItem.v.Skip() {
148 selItem.v.TFAddr = tfaddr.TFAddr{}
149 selItem.textinput.Model.SetValue("")
150 } else {
151 selItem.v.TFAddr = selItem.v.TFAddrCache
152 selItem.textinput.Model.SetValue(selItem.v.TFAddr.String())
153 }
154
155 m.list.SetItem(selItem.idx, selItem)
156 return m, nil
157 case key.Matches(msg, m.listkeys.error):
158 sel := m.list.SelectedItem()
159 if sel == nil {
160 return m, nil
161 }
162 selItem := sel.(Item)
163 if selItem.v.ImportError == nil {
164 return m, nil
165 }
166 return m, aztfexportclient.ShowImportError(selItem.v, selItem.idx, m.importList(false))
167 case key.Matches(msg, m.listkeys.recommendation):
168 sel := m.list.SelectedItem()
169 if sel == nil {

Callers 1

NewImportItemDelegateFunction · 0.45

Calls 10

isUserTypingMethod · 0.95
isNothingToImportMethod · 0.95
userInputsAreValidMethod · 0.95
importListMethod · 0.95
StartImportFunction · 0.92
ShowImportErrorFunction · 0.92
QuitFunction · 0.92
SkipMethod · 0.80
WriteResourceMappingMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected