Skip to content

Commit

Permalink
Merge pull request #118 from Threagile/fix-interactive-mode
Browse files Browse the repository at this point in the history
fixed interactive mode, fixed script any/all/count/contains expressions
  • Loading branch information
joreiche authored Nov 19, 2024
2 parents 7026c2c + a9bf67d commit bab72ae
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ stats.json
/config.json
/config.yaml
/tmp/
/threagile.yaml
72 changes: 72 additions & 0 deletions internal/threagile/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import (
)

type Config struct {
ConfigGetter
ConfigSetter

BuildTimestampValue string `json:"BuildTimestamp,omitempty" yaml:"BuildTimestamp"`
VerboseValue bool `json:"Verbose,omitempty" yaml:"Verbose"`
InteractiveValue bool `json:"Interactive,omitempty" yaml:"Interactive"`
Expand Down Expand Up @@ -65,6 +68,75 @@ type Config struct {
ReportConfigurationValue report.ReportConfiguation `json:"ReportConfiguration" yaml:"ReportConfiguration"`
}

type ConfigGetter interface {
GetBuildTimestamp() string
GetVerbose() bool
GetInteractive() bool
GetAppFolder() string
GetPluginFolder() string
GetDataFolder() string
GetOutputFolder() string
GetServerFolder() string
GetTempFolder() string
GetKeyFolder() string
GetTechnologyFilename() string
GetInputFile() string
GetDataFlowDiagramFilenamePNG() string
GetDataAssetDiagramFilenamePNG() string
GetDataFlowDiagramFilenameDOT() string
GetDataAssetDiagramFilenameDOT() string
GetReportFilename() string
GetExcelRisksFilename() string
GetExcelTagsFilename() string
GetJsonRisksFilename() string
GetJsonTechnicalAssetsFilename() string
GetJsonStatsFilename() string
GetReportLogoImagePath() string
GetTemplateFilename() string
GetRiskRulePlugins() []string
GetSkipRiskRules() []string
GetExecuteModelMacro() string
GetRiskExcelConfigHideColumns() []string
GetRiskExcelConfigSortByColumns() []string
GetRiskExcelConfigWidthOfColumns() map[string]float64
GetRiskExcelWrapText() bool
GetRiskExcelShrinkColumnsToFit() bool
GetRiskExcelColorText() bool
GetServerMode() bool
GetDiagramDPI() int
GetServerPort() int
GetGraphvizDPI() int
GetMinGraphvizDPI() int
GetMaxGraphvizDPI() int
GetBackupHistoryFilesToKeep() int
GetAddModelTitle() bool
GetKeepDiagramSourceFiles() bool
GetIgnoreOrphanedRiskTracking() bool
GetAttractiveness() Attractiveness
GetReportConfiguration() report.ReportConfiguation
GetThreagileVersion() string
GetProgressReporter() types.ProgressReporter
GetReportConfigurationHideChapters() map[report.ChaptersToShowHide]bool
}

type ConfigSetter interface {
SetVerbose(verbose bool)
SetInteractive(interactive bool)
SetAppFolder(appFolder string)
SetPluginFolder(pluginFolder string)
SetOutputFolder(outputFolder string)
SetServerFolder(serverFolder string)
SetTempFolder(tempFolder string)
SetInputFile(inputFile string)
SetTemplateFilename(templateFilename string)
SetRiskRulePlugins(riskRulePlugins []string)
SetSkipRiskRules(skipRiskRules []string)
SetServerMode(serverMode bool)
SetDiagramDPI(diagramDPI int)
SetServerPort(serverPort int)
SetIgnoreOrphanedRiskTracking(ignoreOrphanedRiskTracking bool)
}

func (c *Config) Defaults(buildTimestamp string) *Config {
*c = Config{
BuildTimestampValue: buildTimestamp,
Expand Down
10 changes: 8 additions & 2 deletions internal/threagile/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,19 @@ func (what *Threagile) initRoot() *Threagile {
what.rootCmd.PersistentFlags().BoolVar(&what.flags.generateTagsExcelFlag, generateTagsExcelFlagName, true, "generate tags excel")
what.rootCmd.PersistentFlags().BoolVar(&what.flags.generateReportPDFFlag, generateReportPDFFlagName, true, "generate report pdf, including diagrams")
what.rootCmd.PersistentFlags().BoolVar(&what.flags.generateReportADOCFlag, generateReportADOCFlagName, true, "generate report adoc, including diagrams")

_ = what.rootCmd.PersistentFlags().Parse(os.Args[1:])

return what
}

func (what *Threagile) run(cmd *cobra.Command, _ []string) {
if !what.flags.interactiveFlag {
cmd.Println("Please add the --interactive flag to run in interactive mode.")
return
cfg := what.readConfig(cmd, what.buildTimestamp)
if !cfg.GetInteractive() {
cmd.Println("Please add the --interactive flag to run in interactive mode.")
return
}
}

completer := readline.NewPrefixCompleter()
Expand Down
5 changes: 5 additions & 0 deletions internal/threagile/threagile.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ func (what *Threagile) Execute() {
what.rootCmd.Println(err)
os.Exit(1)
}

cfg := what.readConfig(what.rootCmd, what.buildTimestamp)
if what.flags.interactiveFlag || cfg.GetInteractive() {
what.run(what.rootCmd, nil)
}
}

func (what *Threagile) Init(buildTimestamp string) *Threagile {
Expand Down
3 changes: 3 additions & 0 deletions pkg/risks/script/expressions/all-expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ func (what *AllExpression) evalBool(scope *common.Scope, inValue common.Value) (
case common.Value:
return what.evalBool(scope, common.SomeValue(castValue.Value(), inValue.Event()))

case nil:
return common.SomeBoolValue(false, nil), "", nil

default:
return common.EmptyBoolValue(), what.Literal(), fmt.Errorf("failed to eval all-expression: expected iterable type, got %T", inValue)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/risks/script/expressions/any-expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ func (what *AnyExpression) evalBool(scope *common.Scope, inValue common.Value) (
case common.Value:
return what.evalBool(scope, common.SomeValue(castValue.Value(), inValue.Event()))

case nil:
return common.SomeBoolValue(false, nil), "", nil

default:
return common.EmptyBoolValue(), what.Literal(), fmt.Errorf("failed to eval any-expression: expected iterable type, got %T", inValue)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/risks/script/expressions/contains-expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ func (what *ContainsExpression) evalBool(scope *common.Scope, item common.Value,
case common.Value:
return what.evalBool(scope, item, common.SomeValue(castValue.Value(), inValue.Event()))

case nil:
return common.SomeBoolValue(false, nil), "", nil

default:
return common.EmptyBoolValue(), "", fmt.Errorf("failed to eval contains-expression: expected iterable type, got %T", inValue)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/risks/script/expressions/count-expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ func (what *CountExpression) evalDecimal(scope *common.Scope, inValue common.Val
case common.Value:
return what.evalDecimal(scope, common.SomeValue(castValue.Value(), inValue.Event()))

case nil:
return common.EmptyDecimalValue(), "", nil

default:
return common.EmptyDecimalValue(), what.Literal(), fmt.Errorf("failed to eval all-expression: expected iterable type, got %T", inValue)
}
Expand Down

0 comments on commit bab72ae

Please sign in to comment.