in internal/engine/interactive/interactive.go [594:700]
func NewInteractiveModeModel(
title string,
subscription string,
environment string,
steps []common.Step,
env map[string]string,
markdownSource string,
) (InteractiveModeModel, error) {
// TODO: In the future we should just set the current step for the azure status
// to one as the default.
azureStatus := environments.NewAzureDeploymentStatus()
azureStatus.CurrentStep = 1
totalCodeBlocks := 0
codeBlockState := make(map[int]common.StatefulCodeBlock)
err := az.SetSubscription(subscription)
if err != nil {
logging.GlobalLogger.Errorf("Invalid Config: Failed to set subscription: %s", err)
azureStatus.SetError(err)
environments.ReportAzureStatus(azureStatus, environment)
return InteractiveModeModel{}, err
}
for stepNumber, step := range steps {
azureCodeBlocks := []environments.AzureCodeBlock{}
for blockNumber, block := range step.CodeBlocks {
azureCodeBlocks = append(azureCodeBlocks, environments.AzureCodeBlock{
Command: block.Content,
Description: block.Description,
})
codeBlockState[totalCodeBlocks] = common.StatefulCodeBlock{
StepName: step.Name,
CodeBlock: block,
StepNumber: stepNumber,
CodeBlockNumber: blockNumber,
StdOut: "",
StdErr: "",
Error: nil,
Success: false,
}
totalCodeBlocks += 1
}
azureStatus.AddStep(fmt.Sprintf("%d. %s", stepNumber+1, step.Name), azureCodeBlocks)
}
language := codeBlockState[0].CodeBlock.Language
commandLines := []string{
ui.CommandPrompt(language) + codeBlockState[0].CodeBlock.Content,
}
// Configure extra keybinds used for executing the many/all commands.
executeAllKeybind := key.NewBinding(
key.WithKeys("a"),
key.WithHelp("a", "Execute all remaining commands."),
)
executeManyKeybind := key.NewBinding(
key.WithKeys("m"),
key.WithHelp("m<number><enter>", "Execute the next <number> commands."),
)
pauseKeybind := key.NewBinding(
key.WithKeys("p", "Pause execution of commands."),
)
return InteractiveModeModel{
scenarioTitle: title,
commands: InteractiveModeCommands{
execute: key.NewBinding(
key.WithKeys("e"),
key.WithHelp("e", "Execute the current command."),
),
quit: key.NewBinding(
key.WithKeys("q"),
key.WithHelp("q", "Quit the scenario."),
),
previous: key.NewBinding(
key.WithKeys("left"),
key.WithHelp("←", "Go to the previous command."),
),
next: key.NewBinding(
key.WithKeys("right"),
key.WithHelp("→", "Go to the next command."),
),
// Only enabled when in the azure environment.
executeAll: executeAllKeybind,
executeMany: executeManyKeybind,
pause: pauseKeybind,
},
stepsToBeExecuted: 0,
env: env,
subscription: subscription,
resourceGroupName: "",
azureStatus: azureStatus,
codeBlockState: codeBlockState,
executingCommand: false,
currentCodeBlock: 0,
help: help.New(),
environment: environment,
scenarioCompleted: false,
ready: false,
markdownSource: markdownSource,
CommandLines: commandLines,
}, nil
}