-
-
Notifications
You must be signed in to change notification settings - Fork 104
Add detect blocking IO option to Supervisor options #570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the comm 8000 unity.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add a new detect blocking IO option to the Supervisor options call introduced in home-assistant/supervisor#5746.
📝 WalkthroughWalkthroughA new string flag named "detect-blocking-io" was introduced to the supervisor options command. This flag is now processed alongside other string options, with its value normalized and added to the options map. Shell completion for this flag was also implemented, offering three predefined values. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLI
participant SupervisorOptionsCmd
User->>CLI: Run supervisor options command with --detect-blocking-io flag
CLI->>SupervisorOptionsCmd: Parse flags
SupervisorOptionsCmd->>SupervisorOptionsCmd: Normalize flag key and add to options map
SupervisorOptionsCmd-->>CLI: Execute command logic
CLI-->>User: Output result
User->>CLI: Request shell completion for --detect-blocking-io
CLI->>SupervisorOptionsCmd: Provide completion options
SupervisorOptionsCmd-->>CLI: Return [on, on-at-startup, off]
CLI-->>User: Show completion options
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (1.64.8)Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2 ✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
cmd/supervisor_options.go (3)
31-41
: Consider validating the value before POSTing to the Supervisor API
detect-blocking-io
is appended to the generic[]string
loop and accepted verbatim.
If the caller passes an arbitrary string (typo, upper-case, etc.) it will be forwarded to the Supervisor and only fail there. Doing a quick client-side guard avoids a round-trip and yields clearer feedback.Example:
- val, err := cmd.Flags().GetString(value) - if val != "" && err == nil && cmd.Flags().Changed(value) { - options[strings.ReplaceAll(value, "-", "_")] = val - } + val, err := cmd.Flags().GetString(value) + if val == "" || err != nil || !cmd.Flags().Changed(value) { + continue + } + if value == "detect-blocking-io" { + switch val { + case "on", "on-at-startup", "off": + default: + return fmt.Errorf("invalid value for --detect-blocking-io: %s", val) + } + } + options[strings.ReplaceAll(value, "-", "_")] = val
83-83
: Minor wording nit – follow existing flag descriptionsOther flags document accepted values without parentheses (e.g. Channel to track stable|beta|dev).
For consistency drop the parentheses and mirror that pattern:
"Detect blocking IO: on|on-at-startup|off"
102-104
: Improve shell completion by filtering on user inputThe completion callback always returns all three candidates, ignoring the
toComplete
prefix. Filtering improves UX and is already trivial withstrings.HasPrefix
.-supervisorOptionsCmd.RegisterFlagCompletionFunc("detect-blocking-io", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - return []string{"on", "on-at-startup", "off"}, cobra.ShellCompDirectiveNoFileComp - }) +supervisorOptionsCmd.RegisterFlagCompletionFunc("detect-blocking-io", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { + candidates := []string{"on", "on-at-startup", "off"} + var filtered []string + for _, c := range candidates { + if strings.HasPrefix(c, toComplete) { + filtered = append(filtered, c) + } + } + return filtered, cobra.ShellCompDirectiveNoFileComp + })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting
📒 Files selected for processing (1)
cmd/supervisor_options.go
(3 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`*/**(html|markdown|md)`: - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure t...
*/**(html|markdown|md)
: - For instructional content in documentation, use a direct and authoritative tone. Avoid expressions of politeness such as 'may' or 'please', and ensure the goal of the instruction is fronted.
- Apply the Microsoft Style Guide to ensure documentation maintains clarity and conciseness.
- In step-by-step instructions, front the location phrase in the instructional sentence.
- In step-by-step instructions, front the 'goal' in the instructional sentence.
- In step-by-step instructions, if in doubt what to front, front the 'goal' before the location phrase in the instructional sentence.
- do not hyphenate terms like 'top-right' or 'bottom-left' with 'corner'
cmd/supervisor_options.go
`*/**(html|markdown|md)`: - Use bold to mark UI strings. - If "" are used to mark UI strings, replace them by bold.
*/**(html|markdown|md)
: - Use bold to mark UI strings.
- If "" are used to mark UI strings, replace them by bold.
cmd/supervisor_options.go
`*/**(html|markdown|md)`: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"
*/**(html|markdown|md)
: - Be brief in your replies and don't add fluff like "thank you for..." and "Please let me know if"
cmd/supervisor_options.go
`*/**(html|markdown|md)`: - Use sentence-style capitalization also in headings.
*/**(html|markdown|md)
: - Use sentence-style capitalization also in headings.
cmd/supervisor_options.go
`*/**(html|markdown|md)`: do not comment on HTML used for icons
*/**(html|markdown|md)
: do not comment on HTML used for icons
cmd/supervisor_options.go
`*/**(html|markdown|md)`: Avoid flagging inline HTML for embedding videos in future reviews for this repository.
*/**(html|markdown|md)
: Avoid flagging inline HTML for embedding videos in future reviews for this repository.
cmd/supervisor_options.go
@@ -97,6 +99,9 @@ func init() { | |||
supervisorOptionsCmd.RegisterFlagCompletionFunc("channel", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | |||
return []string{"stable", "beta", "dev"}, cobra.ShellCompDirectiveNoFileComp | |||
}) | |||
supervisorOptionsCmd.RegisterFlagCompletionFunc("detect-blocking-io", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | |||
return []string{"on", "on-at-startup", "off"}, cobra.ShellCompDirectiveNoFileComp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return []string{"on", "on-at-startup", 8000 "off"}, cobra.ShellCompDirectiveNoFileComp | |
return []string{"on", "on_at_startup", "off"}, cobra.ShellCompDirectiveNoFileComp |
Supervisor expects on_at_startup
not on-at-startup
for the value of this field. Alternatively we can handle it above but I think you'd have to remove detect-blocking-io
from the loop and handle it separately. We cannot just do this in the loop:
options[strings.ReplaceAll(value, "-", "_")] = strings.ReplaceAll(val, "-", "_")
Because we can't blindly replace dashes with underscores in values for hostname
or timezone
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I think this is the only place in the API where we use underlines in values. E.g. the networking API uses dashes in constant string values (e.g. stable-privacy
or wpa-psk
). Those are not even directly mapped to NM, so we could have used anything there, It seems on_at_startup
is the oddball here. Since this is really a new API and very unlikely used to be used anywhere just yet, I'd suggest to just change this on Superviser API side...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR to change the API endpoint: home-assistant/supervisor#5964
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Add a new detect blocking IO option to the Supervisor options call introduced in home-assistant/supervisor#5746.
Summary by CodeRabbit