Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
hirenko-v authored Sep 20, 2024
1 parent ca4123a commit bb59412
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions cmd/msg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,40 +223,44 @@ func showBothSelects(firstSelection, secondSelection string) executor.ExecuteOut
// Show second dropdown if the first selection is made
if firstSelection != "" {

sections[0].Selects.Items = append(sections[0].Selects.Items, api.Select{
Name: "second",
Command: cmdPrefix("select_second"),
OptionGroups: []api.OptionGroup{
{
Name: "Second Group",
Options: []api.OptionItem{
{Name: "true", Value: "-i true"},
{Name: "false", Value: "-i false"},
},
},
},
})
}

// Only add the button if both selections are made
if firstSelection != "" && secondSelection != "" {

// Run the script to get dynamic options
scriptOutput, err := runScript(firstSelection)
if err != nil {
log.Fatalf("Error running script: %v", err)
}
// Convert the script output options to a JSON string for displaying in the code block.
optionsJSON, err := json.MarshalIndent(scriptOutput.Options, "", " ")
if err != nil {
log.Fatalf("Error converting options to JSON: %v", err)
}

// Create multiple dropdowns based on the options in the script output
for _, option := range scriptOutput.Options {
var dropdownOptions []api.OptionItem
for _, value := range option.Values {
dropdownOptions = append(dropdownOptions, api.OptionItem{
Name: value,
Value: fmt.Sprintf("%s %s", option.Flags[0], value), // Using the first flag for the command
})
}

// Add each dynamic dropdown to the section
sections[0].Selects.Items = append(sections[0].Selects.Items, api.Select{
Name: option.Description, // Use the option description as the dropdown name
Command: cmdPrefix("select_second"),
OptionGroups: []api.OptionGroup{
{
Name: option.Description, // Use the option description as the group name
Options: dropdownOptions, // Use the dynamically created options
},
},
})
}
}

// Only add the button if both selections are made
if firstSelection != "" && secondSelection != "" {

code := fmt.Sprintf("run %s %s", firstSelection, secondSelection)
sections = append(sections, api.Section{
Base: api.Base{
Body: api.Body{
CodeBlock: string(optionsJSON),
CodeBlock: code,
},
},
Buttons: []api.Button{
Expand Down

0 comments on commit bb59412

Please sign in to comment.