| 107 | } |
| 108 | |
| 109 | func (m Model) View() string { |
| 110 | msg := "" |
| 111 | if len(m.l) > m.idx { |
| 112 | item := m.l[m.idx] |
| 113 | if item.Skip() { |
| 114 | msg = fmt.Sprintf(" Skipping %s...", item.TFResourceId) |
| 115 | } else { |
| 116 | msg = fmt.Sprintf(" Importing %s...", item.TFResourceId) |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | s := fmt.Sprintf(" %s\n\n", msg) |
| 121 | for _, res := range m.results { |
| 122 | // This indicates the state before the item is inserted as the to results. |
| 123 | if res.item.TFResourceId == "" { |
| 124 | s += "...\n" |
| 125 | } else { |
| 126 | switch { |
| 127 | case res.item.Skip(): |
| 128 | s += fmt.Sprintf("%s %s skipped\n", res.emoji, res.item.TFResourceId) |
| 129 | default: |
| 130 | if res.item.ImportError == nil { |
| 131 | s += fmt.Sprintf("%s %s import successfully\n", res.emoji, res.item.TFResourceId) |
| 132 | } else { |
| 133 | s += fmt.Sprintf("%s %s import failed\n", res.emoji, res.item.TFResourceId) |
| 134 | } |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | s += "\n\n" + m.progress.View() |
| 140 | |
| 141 | return s |
| 142 | } |
| 143 | |
| 144 | func (m Model) iterationDone() bool { |
| 145 | return m.idx >= len(m.l) |