-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The changes introduced by this PR as follows: * Adds `ie interactive` implementation to support executing markdown documents interactively. * Adds `ie inspect` to view the parsed data of a markdown document produced by Innovation engines parser. This feature is still experimental and only shows some of the parsing output for now. * Updates the markdown parser to associate the last paragraph of markdown document as the description for a codeblock. * Adds a completely new rendering system using `bubble-tea` to support interactive mode. Both `ie execute` and `ie test` will be rewritten in the future to utilize a similar rendering implementation. * Changes the status update for integration with the azure extensionto nest codeblocks underneath steps and for codeblocks to include their descriptions for learn mode.
- Loading branch information
Showing
25 changed files
with
1,210 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/Azure/InnovationEngine/internal/engine" | ||
"github.com/Azure/InnovationEngine/internal/logging" | ||
"github.com/Azure/InnovationEngine/internal/ui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Register the command with our command runner. | ||
func init() { | ||
rootCommand.AddCommand(inspectCommand) | ||
|
||
// String flags | ||
inspectCommand.PersistentFlags(). | ||
String("correlation-id", "", "Adds a correlation ID to the user agent used by a scenarios azure-cli commands.") | ||
inspectCommand.PersistentFlags(). | ||
String("subscription", "", "Sets the subscription ID used by a scenarios azure-cli commands. Will rely on the default subscription if not set.") | ||
inspectCommand.PersistentFlags(). | ||
String("working-directory", ".", "Sets the working directory for innovation engine to operate out of. Restores the current working directory when finished.") | ||
|
||
// StringArray flags | ||
inspectCommand.PersistentFlags(). | ||
StringArray("var", []string{}, "Sets an environment variable for the scenario. Format: --var <key>=<value>") | ||
} | ||
|
||
var inspectCommand = &cobra.Command{ | ||
Use: "inspect", | ||
Short: "Execute a document in inspect mode.", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
markdownFile := args[0] | ||
if markdownFile == "" { | ||
logging.GlobalLogger.Errorf("Error: No markdown file specified.") | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
|
||
environmentVariables, _ := cmd.Flags().GetStringArray("var") | ||
// features, _ := cmd.Flags().GetStringArray("feature") | ||
|
||
// Parse the environment variables from the command line into a map | ||
cliEnvironmentVariables := make(map[string]string) | ||
for _, environmentVariable := range environmentVariables { | ||
keyValuePair := strings.SplitN(environmentVariable, "=", 2) | ||
if len(keyValuePair) != 2 { | ||
logging.GlobalLogger.Errorf( | ||
"Error: Invalid environment variable format: %s", | ||
environmentVariable, | ||
) | ||
fmt.Printf("Error: Invalid environment variable format: %s", environmentVariable) | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
|
||
cliEnvironmentVariables[keyValuePair[0]] = keyValuePair[1] | ||
} | ||
// Parse the markdown file and create a scenario | ||
scenario, err := engine.CreateScenarioFromMarkdown( | ||
markdownFile, | ||
[]string{"bash", "azurecli", "azurecli-inspect", "terraform"}, | ||
cliEnvironmentVariables, | ||
) | ||
if err != nil { | ||
logging.GlobalLogger.Errorf("Error creating scenario: %s", err) | ||
fmt.Printf("Error creating scenario: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
if err != nil { | ||
logging.GlobalLogger.Errorf("Error creating engine: %s", err) | ||
fmt.Printf("Error creating engine: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println(ui.ScenarioTitleStyle.Render(scenario.Name)) | ||
for stepNumber, step := range scenario.Steps { | ||
stepTitle := fmt.Sprintf(" %d. %s\n", stepNumber+1, step.Name) | ||
fmt.Println(ui.StepTitleStyle.Render(stepTitle)) | ||
for codeBlockNumber, codeBlock := range step.CodeBlocks { | ||
fmt.Println( | ||
ui.InteractiveModeCodeBlockDescriptionStyle.Render( | ||
fmt.Sprintf( | ||
" %d.%d %s", | ||
stepNumber+1, | ||
codeBlockNumber+1, | ||
codeBlock.Description, | ||
), | ||
), | ||
) | ||
fmt.Print( | ||
ui.IndentMultiLineCommand( | ||
fmt.Sprintf( | ||
" %s", | ||
ui.InteractiveModeCodeBlockStyle.Render( | ||
codeBlock.Content, | ||
), | ||
), | ||
6), | ||
) | ||
fmt.Println() | ||
} | ||
} | ||
|
||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,107 @@ | ||
package commands | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/Azure/InnovationEngine/internal/engine" | ||
"github.com/Azure/InnovationEngine/internal/logging" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Register the command with our command runner. | ||
func init() { | ||
rootCommand.AddCommand(interactiveCommand) | ||
|
||
// String flags | ||
interactiveCommand.PersistentFlags(). | ||
String("correlation-id", "", "Adds a correlation ID to the user agent used by a scenarios azure-cli commands.") | ||
interactiveCommand.PersistentFlags(). | ||
String("subscription", "", "Sets the subscription ID used by a scenarios azure-cli commands. Will rely on the default subscription if not set.") | ||
interactiveCommand.PersistentFlags(). | ||
String("working-directory", ".", "Sets the working directory for innovation engine to operate out of. Restores the current working directory when finished.") | ||
|
||
// StringArray flags | ||
interactiveCommand.PersistentFlags(). | ||
StringArray("var", []string{}, "Sets an environment variable for the scenario. Format: --var <key>=<value>") | ||
} | ||
|
||
var interactiveCommand = &cobra.Command{ | ||
Use: "interactive", | ||
Short: "Execute a document in interactive mode.", | ||
} | ||
Run: func(cmd *cobra.Command, args []string) { | ||
markdownFile := args[0] | ||
if markdownFile == "" { | ||
logging.GlobalLogger.Errorf("Error: No markdown file specified.") | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
|
||
// / Register the command with our command runner. | ||
func init() { | ||
rootCommand.AddCommand(interactiveCommand) | ||
verbose, _ := cmd.Flags().GetBool("verbose") | ||
doNotDelete, _ := cmd.Flags().GetBool("do-not-delete") | ||
|
||
subscription, _ := cmd.Flags().GetString("subscription") | ||
correlationId, _ := cmd.Flags().GetString("correlation-id") | ||
environment, _ := cmd.Flags().GetString("environment") | ||
workingDirectory, _ := cmd.Flags().GetString("working-directory") | ||
|
||
environmentVariables, _ := cmd.Flags().GetStringArray("var") | ||
// features, _ := cmd.Flags().GetStringArray("feature") | ||
|
||
// Known features | ||
renderValues := false | ||
|
||
// Parse the environment variables from the command line into a map | ||
cliEnvironmentVariables := make(map[string]string) | ||
for _, environmentVariable := range environmentVariables { | ||
keyValuePair := strings.SplitN(environmentVariable, "=", 2) | ||
if len(keyValuePair) != 2 { | ||
logging.GlobalLogger.Errorf( | ||
"Error: Invalid environment variable format: %s", | ||
environmentVariable, | ||
) | ||
fmt.Printf("Error: Invalid environment variable format: %s", environmentVariable) | ||
cmd.Help() | ||
os.Exit(1) | ||
} | ||
|
||
cliEnvironmentVariables[keyValuePair[0]] = keyValuePair[1] | ||
} | ||
// Parse the markdown file and create a scenario | ||
scenario, err := engine.CreateScenarioFromMarkdown( | ||
markdownFile, | ||
[]string{"bash", "azurecli", "azurecli-interactive", "terraform"}, | ||
cliEnvironmentVariables, | ||
) | ||
if err != nil { | ||
logging.GlobalLogger.Errorf("Error creating scenario: %s", err) | ||
fmt.Printf("Error creating scenario: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
innovationEngine, err := engine.NewEngine(engine.EngineConfiguration{ | ||
Verbose: verbose, | ||
DoNotDelete: doNotDelete, | ||
Subscription: subscription, | ||
CorrelationId: correlationId, | ||
Environment: environment, | ||
WorkingDirectory: workingDirectory, | ||
RenderValues: renderValues, | ||
}) | ||
|
||
if err != nil { | ||
logging.GlobalLogger.Errorf("Error creating engine: %s", err) | ||
fmt.Printf("Error creating engine: %s", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Execute the scenario | ||
err = innovationEngine.InteractWithScenario(scenario) | ||
if err != nil { | ||
logging.GlobalLogger.Errorf("Error executing scenario: %s", err) | ||
fmt.Printf("Error executing scenario: %s", err) | ||
os.Exit(1) | ||
} | ||
}, | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.