11package commands
22
33import (
4+ "errors"
45 "fmt"
5- "os"
66
77 "github.com/Azure/InnovationEngine/internal/engine"
8- "github.com/Azure/InnovationEngine/internal/logging"
98 "github.com/spf13/cobra"
109)
1110
@@ -22,11 +21,10 @@ var testCommand = &cobra.Command{
2221 Use : "test [markdown file]" ,
2322 Args : cobra .MinimumNArgs (1 ),
2423 Short : "Test document commands against it's expected outputs." ,
25- Run : func (cmd * cobra.Command , args []string ) {
24+ RunE : func (cmd * cobra.Command , args []string ) error {
2625 markdownFile := args [0 ]
2726 if markdownFile == "" {
28- cmd .Help ()
29- return
27+ return errors .New ("no markdown file specified" )
3028 }
3129
3230 verbose , _ := cmd .Flags ().GetBool ("verbose" )
@@ -39,9 +37,7 @@ var testCommand = &cobra.Command{
3937 CorrelationId : "" ,
4038 })
4139 if err != nil {
42- logging .GlobalLogger .Errorf ("Error creating engine %s" , err )
43- fmt .Printf ("Error creating engine %s" , err )
44- os .Exit (1 )
40+ return fmt .Errorf ("creating engine: %w" , err )
4541 }
4642
4743 scenario , err := engine .CreateScenarioFromMarkdown (
@@ -50,11 +46,13 @@ var testCommand = &cobra.Command{
5046 nil ,
5147 )
5248 if err != nil {
53- logging .GlobalLogger .Errorf ("Error creating scenario %s" , err )
54- fmt .Printf ("Error creating engine %s" , err )
55- os .Exit (1 )
49+ return fmt .Errorf ("creating scenario: %w" , err )
5650 }
5751
58- innovationEngine .TestScenario (scenario )
52+ if err := innovationEngine .TestScenario (scenario ); err != nil {
53+ return fmt .Errorf ("testing scenario: %w" , err )
54+ }
55+
56+ return nil
5957 },
6058}
0 commit comments