From c2ef6a8d42c6896b1d5e05072aad07f4c6d39293 Mon Sep 17 00:00:00 2001 From: lanath Date: Mon, 2 Dec 2024 11:33:02 +0100 Subject: [PATCH] feat(ctl): we are now always asking the user for suricata.interfaces. 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 --- cmd/ctl/compose/init.go | 15 ++++++++++++++- internal/handlers/flags.go | 9 +++++++++ internal/models/parameter.go | 4 ++++ internal/models/parameters.go | 6 ++++-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/cmd/ctl/compose/init.go b/cmd/ctl/compose/init.go index 958f643..4ec49d0 100644 --- a/cmd/ctl/compose/init.go +++ b/cmd/ctl/compose/init.go @@ -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" ) @@ -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) @@ -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) @@ -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 @@ -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, diff --git a/internal/handlers/flags.go b/internal/handlers/flags.go index 271cb64..99264d8 100644 --- a/internal/handlers/flags.go +++ b/internal/handlers/flags.go @@ -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", diff --git a/internal/models/parameter.go b/internal/models/parameter.go index 66c56ef..01f328f 100644 --- a/internal/models/parameter.go +++ b/internal/models/parameter.go @@ -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 diff --git a/internal/models/parameters.go b/internal/models/parameters.go index 4a32100..51c2621 100644 --- a/internal/models/parameters.go +++ b/internal/models/parameters.go @@ -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