Skip to content

Commit bab72ae

Browse files
authored
Merge pull request #118 from Threagile/fix-interactive-mode
fixed interactive mode, fixed script any/all/count/contains expressions
2 parents 7026c2c + a9bf67d commit bab72ae

File tree

8 files changed

+98
-2
lines changed

8 files changed

+98
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ stats.json
3434
/config.json
3535
/config.yaml
3636
/tmp/
37+
/threagile.yaml

internal/threagile/config.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import (
1717
)
1818

1919
type Config struct {
20+
ConfigGetter
21+
ConfigSetter
22+
2023
BuildTimestampValue string `json:"BuildTimestamp,omitempty" yaml:"BuildTimestamp"`
2124
VerboseValue bool `json:"Verbose,omitempty" yaml:"Verbose"`
2225
InteractiveValue bool `json:"Interactive,omitempty" yaml:"Interactive"`
@@ -65,6 +68,75 @@ type Config struct {
6568
ReportConfigurationValue report.ReportConfiguation `json:"ReportConfiguration" yaml:"ReportConfiguration"`
6669
}
6770

71+
type ConfigGetter interface {
72+
GetBuildTimestamp() string
73+
GetVerbose() bool
74+
GetInteractive() bool
75+
GetAppFolder() string
76+
GetPluginFolder() string
77+
GetDataFolder() string
78+
GetOutputFolder() string
79+
GetServerFolder() string
80+
GetTempFolder() string
81+
GetKeyFolder() string
82+
GetTechnologyFilename() string
83+
GetInputFile() string
84+
GetDataFlowDiagramFilenamePNG() string
85+
GetDataAssetDiagramFilenamePNG() string
86+
GetDataFlowDiagramFilenameDOT() string
87+
GetDataAssetDiagramFilenameDOT() string
88+
GetReportFilename() string
89+
GetExcelRisksFilename() string
90+
GetExcelTagsFilename() string
91+
GetJsonRisksFilename() string
92+
GetJsonTechnicalAssetsFilename() string
93+
GetJsonStatsFilename() string
94+
GetReportLogoImagePath() string
95+
GetTemplateFilename() string
96+
GetRiskRulePlugins() []string
97+
GetSkipRiskRules() []string
98+
GetExecuteModelMacro() string
99+
GetRiskExcelConfigHideColumns() []string
100+
GetRiskExcelConfigSortByColumns() []string
101+
GetRiskExcelConfigWidthOfColumns() map[string]float64
102+
GetRiskExcelWrapText() bool
103+
GetRiskExcelShrinkColumnsToFit() bool
104+
GetRiskExcelColorText() bool
105+
GetServerMode() bool
106+
GetDiagramDPI() int
107+
GetServerPort() int
108+
GetGraphvizDPI() int
109+
GetMinGraphvizDPI() int
110+
GetMaxGraphvizDPI() int
111+
GetBackupHistoryFilesToKeep() int
112+
GetAddModelTitle() bool
113+
GetKeepDiagramSourceFiles() bool
114+
GetIgnoreOrphanedRiskTracking() bool
115+
GetAttractiveness() Attractiveness
116+
GetReportConfiguration() report.ReportConfiguation
117+
GetThreagileVersion() string
118+
GetProgressReporter() types.ProgressReporter
119+
GetReportConfigurationHideChapters() map[report.ChaptersToShowHide]bool
120+
}
121+
122+
type ConfigSetter interface {
123+
SetVerbose(verbose bool)
124+
SetInteractive(interactive bool)
125+
SetAppFolder(appFolder string)
126+
SetPluginFolder(pluginFolder string)
127+
SetOutputFolder(outputFolder string)
128+
SetServerFolder(serverFolder string)
129+
SetTempFolder(tempFolder string)
130+
SetInputFile(inputFile string)
131+
SetTemplateFilename(templateFilename string)
132+
SetRiskRulePlugins(riskRulePlugins []string)
133+
SetSkipRiskRules(skipRiskRules []string)
134+
SetServerMode(serverMode bool)
135+
SetDiagramDPI(diagramDPI int)
136+
SetServerPort(serverPort int)
137+
SetIgnoreOrphanedRiskTracking(ignoreOrphanedRiskTracking bool)
138+
}
139+
68140
func (c *Config) Defaults(buildTimestamp string) *Config {
69141
*c = Config{
70142
BuildTimestampValue: buildTimestamp,

internal/threagile/root.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,19 @@ func (what *Threagile) initRoot() *Threagile {
8282
what.rootCmd.PersistentFlags().BoolVar(&what.flags.generateTagsExcelFlag, generateTagsExcelFlagName, true, "generate tags excel")
8383
what.rootCmd.PersistentFlags().BoolVar(&what.flags.generateReportPDFFlag, generateReportPDFFlagName, true, "generate report pdf, including diagrams")
8484
what.rootCmd.PersistentFlags().BoolVar(&what.flags.generateReportADOCFlag, generateReportADOCFlagName, true, "generate report adoc, including diagrams")
85+
86+
_ = what.rootCmd.PersistentFlags().Parse(os.Args[1:])
87+
8588
return what
8689
}
8790

8891
func (what *Threagile) run(cmd *cobra.Command, _ []string) {
8992
if !what.flags.interactiveFlag {
90-
cmd.Println("Please add the --interactive flag to run in interactive mode.")
91-
return
93+
cfg := what.readConfig(cmd, what.buildTimestamp)
94+
if !cfg.GetInteractive() {
95+
cmd.Println("Please add the --interactive flag to run in interactive mode.")
96+
return
97+
}
9298
}
9399

94100
completer := readline.NewPrefixCompleter()

internal/threagile/threagile.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ func (what *Threagile) Execute() {
1818
what.rootCmd.Println(err)
1919
os.Exit(1)
2020
}
21+
22+
cfg := what.readConfig(what.rootCmd, what.buildTimestamp)
23+
if what.flags.interactiveFlag || cfg.GetInteractive() {
24+
what.run(what.rootCmd, nil)
25+
}
2126
}
2227

2328
func (what *Threagile) Init(buildTimestamp string) *Threagile {

pkg/risks/script/expressions/all-expression.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ func (what *AllExpression) evalBool(scope *common.Scope, inValue common.Value) (
185185
case common.Value:
186186
return what.evalBool(scope, common.SomeValue(castValue.Value(), inValue.Event()))
187187

188+
case nil:
189+
return common.SomeBoolValue(false, nil), "", nil
190+
188191
default:
189192
return common.EmptyBoolValue(), what.Literal(), fmt.Errorf("failed to eval all-expression: expected iterable type, got %T", inValue)
190193
}

pkg/risks/script/expressions/any-expression.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ func (what *AnyExpression) evalBool(scope *common.Scope, inValue common.Value) (
182182
case common.Value:
183183
return what.evalBool(scope, common.SomeValue(castValue.Value(), inValue.Event()))
184184

185+
case nil:
186+
return common.SomeBoolValue(false, nil), "", nil
187+
185188
default:
186189
return common.EmptyBoolValue(), what.Literal(), fmt.Errorf("failed to eval any-expression: expected iterable type, got %T", inValue)
187190
}

pkg/risks/script/expressions/contains-expression.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ func (what *ContainsExpression) evalBool(scope *common.Scope, item common.Value,
120120
case common.Value:
121121
return what.evalBool(scope, item, common.SomeValue(castValue.Value(), inValue.Event()))
122122

123+
case nil:
124+
return common.SomeBoolValue(false, nil), "", nil
125+
123126
default:
124127
return common.EmptyBoolValue(), "", fmt.Errorf("failed to eval contains-expression: expected iterable type, got %T", inValue)
125128
}

pkg/risks/script/expressions/count-expression.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,9 @@ func (what *CountExpression) evalDecimal(scope *common.Scope, inValue common.Val
183183
case common.Value:
184184
return what.evalDecimal(scope, common.SomeValue(castValue.Value(), inValue.Event()))
185185

186+
case nil:
187+
return common.EmptyDecimalValue(), "", nil
188+
186189
default:
187190
return common.EmptyDecimalValue(), what.Literal(), fmt.Errorf("failed to eval all-expression: expected iterable type, got %T", inValue)
188191
}

0 commit comments

Comments
 (0)