Skip to content

Add --feature-flag option to supervisor options command#649

Merged
agners merged 3 commits intomasterfrom
feature-toggles
Apr 23, 2026
Merged

Add --feature-flag option to supervisor options command#649
agners merged 3 commits intomasterfrom
feature-toggles

Conversation

@mdegat01
Copy link
Copy Markdown
Contributor

@mdegat01 mdegat01 commented Apr 14, 2026

Adds CLI support for the development feature toggle system introduced in home-assistant/supervisor#6719.

Usage

# Enable a feature flag (explicit)
ha supervisor options --feature-flag supervisor_v2_api=true

# Enable a feature flag (bare name defaults to true)
ha supervisor options --feature-flag supervisor_v2_api

# Disable a feature flag
ha supervisor options --feature-flag supervisor_v2_api=false

# Set multiple flags at once
ha supervisor options --feature-flag supervisor_v2_api=true --feature-flag other_flag=false

Tab completion calls /supervisor/info and suggests each known flag with its opposite value (e.g. supervisor_v2_api=true\tcurrently false), making it immediately actionable.

Summary by CodeRabbit

  • New Features
    • Added --feature-flag option to supervisor options command, enabling configuration of feature flags with name=true|false syntax or bare names for true values. Includes shell completions for available flags.

Allows users to enable/disable development feature flags via:
  ha supervisor options --feature-flag supervisor_v2_api=true
  ha supervisor options --feature-flag supervisor_v2_api  (defaults to true)
  ha supervisor options --feature-flag supervisor_v2_api=false

Multiple flags can be set by repeating the argument. Tab completion
calls /supervisor/info and suggests each flag with its opposite value
(e.g. supervisor_v2_api=true when currently false).

Related: home-assistant/supervisor#6719

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Adds a new --feature-flag CLI option to the ha supervisor options command that accepts name=true|false pairs (or bare names defaulting to true), validates input, and submits feature flags to the backend as a map within the JSON payload. Includes help documentation and shell completions.

Changes

Cohort / File(s) Summary
Feature Flag CLI Option
cmd/supervisor_options.go
Adds --feature-flag option with input validation for boolean values, parsing logic to convert string entries into a map[string]bool, help text documentation with usage examples, and shell completion integration that queries supervisor info for available flags and generates boolean-typed completion candidates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately describes the main change: adding a --feature-flag option to the supervisor options command.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature-toggles

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds CLI support in ha supervisor options for managing Supervisor development feature flags (per the Supervisor’s feature toggle system), including shell completions based on /supervisor/info.

Changes:

  • Adds --feature-flag (repeatable) to set Supervisor development feature flags via supervisor/options.
  • Parses --feature-flag values as name[=true|false] (defaulting to true when =... is omitted).
  • Implements tab-completion for --feature-flag by fetching current flags from /supervisor/info and suggesting toggled values.

Comment thread cmd/supervisor_options.go Outdated
Comment thread cmd/supervisor_options.go
supervisorOptionsCmd.Flags().BoolP("debug-block", "", false, "Enable debug mode with blocking startup")
supervisorOptionsCmd.Flags().BoolP("diagnostics", "", false, "Enable diagnostics mode")
supervisorOptionsCmd.Flags().BoolP("auto-update", "", true, "Enable/disable supervisor auto update")
supervisorOptionsCmd.Flags().StringArrayP("feature-flag", "", []string{}, "Set a development feature flag (name=true|false). Use multiple times for multiple flags.")
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The help text for --feature-flag says (name=true|false), but the implementation also accepts a bare name and defaults it to true. Update the flag description to reflect the supported syntax so users aren’t misled.

Suggested change
supervisorOptionsCmd.Flags().StringArrayP("feature-flag", "", []string{}, "Set a development feature flag (name=true|false). Use multiple times for multiple flags.")
supervisorOptionsCmd.Flags().StringArrayP("feature-flag", "", []string{}, "Set a development feature flag (name[=true|false]). Bare name defaults to true. Use multiple times for multiple flags.")

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems kinda obvious to me, or can be explored if needs to be. No extra documentation needed.

Comment thread cmd/supervisor_options.go
Comment on lines +143 to +147
current, ok := val.(bool)
if !ok {
continue
}
ret = append(ret, fmt.Sprintf("%s=%v\tcurrently %v", name, !current, current))
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

featureFlagCompletions iterates over a Go map, so completion ordering will be nondeterministic between runs/shell invocations. Consider collecting the flag names, sorting them, and then appending suggestions in a stable order to avoid a noisy/unstable completion UX.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't do this in other places right now, so I don't think we need to start it with this PR.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Member

@agners agners left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
cmd/supervisor_options.go (2)

62-80: Minor: inconsistent whitespace handling between name and value.

name is trimmed via strings.TrimSpace, but parts[1] is passed directly to strconv.ParseBool. An input like --feature-flag "foo = true" will trim the name but fail to parse " true". Consider trimming both sides for consistency, or neither.

Proposed tweak
-				val, err = strconv.ParseBool(parts[1])
+				val, err = strconv.ParseBool(strings.TrimSpace(parts[1]))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/supervisor_options.go` around lines 62 - 80, The feature flag parsing
trims the flag name but not the value, so inputs like `foo = true` fail; update
the parsing in the block that uses strings.SplitN, name :=
strings.TrimSpace(parts[0]), and strconv.ParseBool(parts[1]) to also trim the
value before parsing (e.g., call strings.TrimSpace on parts[1] before passing to
strconv.ParseBool and using it to set val) so both name and value handle
surrounding whitespace consistently and error messages still reference the
trimmed name.

132-144: Unchecked type assertion on resp.Result().

Line 137 performs resp.Result().(*helper.Response) without the comma-ok form; a nil or unexpected result type would panic the completion. The existing pattern in cmd/resolution_check.go has the same shape, so this is consistent with the codebase, but worth noting since a panic in a completion function degrades UX silently. Optional to harden here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@cmd/supervisor_options.go` around lines 132 - 144, The featureFlagCompletions
function does an unchecked cast resp.Result().(*helper.Response) which can
panic; change this to the comma-ok form and nil-check the result before using it
(e.g., r, ok := resp.Result().(*helper.Response); if !ok || r == nil { return
nil, cobra.ShellCompDirectiveNoFileComp }), then use r.Result and r.Data for the
subsequent checks; this hardens featureFlagCompletions against unexpected or nil
resp.Result() without altering behavior on success.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@cmd/supervisor_options.go`:
- Around line 62-80: The feature flag parsing trims the flag name but not the
value, so inputs like `foo = true` fail; update the parsing in the block that
uses strings.SplitN, name := strings.TrimSpace(parts[0]), and
strconv.ParseBool(parts[1]) to also trim the value before parsing (e.g., call
strings.TrimSpace on parts[1] before passing to strconv.ParseBool and using it
to set val) so both name and value handle surrounding whitespace consistently
and error messages still reference the trimmed name.
- Around line 132-144: The featureFlagCompletions function does an unchecked
cast resp.Result().(*helper.Response) which can panic; change this to the
comma-ok form and nil-check the result before using it (e.g., r, ok :=
resp.Result().(*helper.Response); if !ok || r == nil { return nil,
cobra.ShellCompDirectiveNoFileComp }), then use r.Result and r.Data for the
subsequent checks; this hardens featureFlagCompletions against unexpected or nil
resp.Result() without altering behavior on success.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ab3fcd39-d5bd-45d3-8d48-852d42c8c62a

📥 Commits

Reviewing files that changed from the base of the PR and between 3e9f19c and 2a361bf.

📒 Files selected for processing (1)
  • cmd/supervisor_options.go

@agners agners merged commit 6a668fc into master Apr 23, 2026
6 checks passed
@agners agners deleted the feature-toggles branch April 23, 2026 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants