MCPcopy
hub / github.com/hashicorp/packer / modeInteractive

Method modeInteractive

command/console.go:131–169  ·  view source on GitHub ↗
(cfg packer.Evaluator)

Source from the content-addressed store, hash-verified

129}
130
131func (c *ConsoleCommand) modeInteractive(cfg packer.Evaluator) int {
132 // Setup the UI so we can output directly to stdout
133 l, err := readline.NewEx(wrappedreadline.Override(&readline.Config{
134 Prompt: "> ",
135 InterruptPrompt: "^C",
136 EOFPrompt: "exit",
137 HistorySearchFold: true,
138 }))
139 if err != nil {
140 c.Ui.Error(fmt.Sprintf(
141 "Error initializing console: %s",
142 err))
143 return 1
144 }
145 for {
146 // Read a line
147 line, err := l.Readline()
148 if err == readline.ErrInterrupt {
149 if len(line) == 0 {
150 break
151 } else {
152 continue
153 }
154 } else if err == io.EOF {
155 break
156 }
157 out, exit, diags := cfg.EvaluateExpression(line)
158 ret := writeDiags(c.Ui, nil, diags)
159 if exit {
160 return ret
161 }
162 c.Ui.Say(out)
163 if exit {
164 return ret
165 }
166 }
167
168 return 0
169}

Callers 1

RunContextMethod · 0.95

Calls 5

OverrideFunction · 0.92
writeDiagsFunction · 0.85
ErrorMethod · 0.65
EvaluateExpressionMethod · 0.65
SayMethod · 0.45

Tested by

no test coverage detected