Skip to content

Commit

Permalink
feat(ctl): we are now always asking the user for suricata.interfaces.…
Browse files Browse the repository at this point in the history
… If their is only 1 interface, we skip the question and use it directly. If there are more than 1, we ask the user to select one. The --default/-d flag is now active by default and replaced by --expert/-E flag that disable defaulting mode
  • Loading branch information
lanathlor committed Dec 2, 2024
1 parent bc5282b commit c2ef6a8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
15 changes: 14 additions & 1 deletion cmd/ctl/compose/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"stamus-ctl/internal/embeds"
flags "stamus-ctl/internal/handlers"
handlers "stamus-ctl/internal/handlers/compose"
"stamus-ctl/internal/logging"
"stamus-ctl/internal/utils"
)

Expand All @@ -38,6 +39,7 @@ func initCmd() *cobra.Command {
}
// Flags
flags.IsDefaultParam.AddAsFlag(cmd, false)
flags.IsExpert.AddAsFlag(cmd, false)
flags.Values.AddAsFlag(cmd, false)
flags.FromFile.AddAsFlag(cmd, false)
flags.Config.AddAsFlag(cmd, false)
Expand Down Expand Up @@ -65,6 +67,7 @@ func ClearNDRCmd() *cobra.Command {
}
// Flags
flags.IsDefaultParam.AddAsFlag(cmd, false)
flags.IsExpert.AddAsFlag(cmd, false)
flags.Values.AddAsFlag(cmd, false)
flags.FromFile.AddAsFlag(cmd, false)
flags.Config.AddAsFlag(cmd, false)
Expand All @@ -80,6 +83,16 @@ func handler(_ *cobra.Command, args []string) error {
if err != nil {
return err
}

if isDefault.(bool) {
logging.Sugar.Info("--default flag is deprecated. It is true by default.")
}

isExpert, err := flags.IsExpert.GetValue()
if err != nil {
return err
}

values, err := flags.Values.GetValue()
if err != nil {
return err
Expand Down Expand Up @@ -117,7 +130,7 @@ func handler(_ *cobra.Command, args []string) error {

// Call handler
initParams := handlers.InitHandlerInputs{
IsDefault: isDefault.(bool),
IsDefault: !isExpert.(bool),
BackupFolderPath: app.DefaultClearNDRPath,
Arbitrary: utils.ExtractArgs(args),
Project: project,
Expand Down
9 changes: 9 additions & 0 deletions internal/handlers/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ var IsDefaultParam = models.Parameter{
Default: models.CreateVariableBool(false),
Usage: "Set to default settings",
}

var IsExpert = models.Parameter{
Name: "expert",
Shorthand: "E",
Type: "bool",
Default: models.CreateVariableBool(false),
Usage: "Set to expert settings",
}

var Values = models.Parameter{
Name: "values",
Shorthand: "v",
Expand Down
4 changes: 4 additions & 0 deletions internal/models/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ func (p *Parameter) AskUser() error {
for _, choice := range p.Choices {
choices = append(choices, *choice.String)
}
if len(choices) == 1 {
p.Variable = CreateVariableString(choices[0])
return nil
}
result, err := selectPrompt(p, choices)
if err != nil {
return err
Expand Down
6 changes: 4 additions & 2 deletions internal/models/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ func (p *Parameters) SetToDefaults() error {
return err
}
// Set all parameters to their default values
for _, param := range *p {
for k, param := range *p {
if param.Type != "optional" && param.Variable.IsNil() {
param.SetToDefault()
if k != "suricata.interfaces" {
param.SetToDefault()
}
}
}
return nil
Expand Down

0 comments on commit c2ef6a8

Please sign in to comment.