-
Notifications
You must be signed in to change notification settings - Fork 11
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 community.
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
fix setting values with absolute key-paths #181
Conversation
analogously to $ ovos-config get -k /location/city/name one can now set values with absolute key paths $ ovos-config set -k /location/city/name -v Mycity
WalkthroughThe changes primarily focus on the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ConfigTool
participant Config
User->>ConfigTool: set(key, value)
ConfigTool->>Config: check if key is absolute_path
alt Absolute Path
ConfigTool->>Config: pathGet(CONFIG, key)
else Relative Path
ConfigTool->>Config: walkDict(CONFIG, key)
end
ConfigTool->>User: return value or error message
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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: 1
🧹 Outside diff range and nitpick comments (1)
ovos_config/__main__.py (1)
389-395
: Consider improving error messages for different path typesThe error message "No key that fits the query" is generic and doesn't distinguish between absolute and relative path searches. Consider providing more specific feedback based on the search type.
Apply this diff to improve error messages:
absolute_path = key.startswith("/") key = key.lstrip("/") if absolute_path: try: tuples = [(key.split("/"), pathGet(CONFIG, key))] except KeyError: console.print(f"[red]Error:[/red] No configuration found at absolute path '/{key}'") exit() else: tuples = list(walkDict(CONFIG, key, full_path=True)) values = [tup[1] for tup in tuples] paths = ["/".join(tup[0]) for tup in tuples] if len(paths) > 1: # ... existing table display code ... elif not paths: - console.print("[red]Error:[/red] No key that fits the query") + if absolute_path: + console.print(f"[red]Error:[/red] No configuration found at absolute path '/{key}'") + else: + console.print(f"[red]Error:[/red] No configuration key matches the query '{key}'") exit()
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
ovos_config/__main__.py
(1 hunks)
🔇 Additional comments (1)
ovos_config/__main__.py (1)
389-391
: LGTM! Implementation successfully adds absolute path support
The changes effectively implement the ability to set values using absolute key paths, mirroring the existing get command's behavior while maintaining backward compatibility with relative path searches.
if absolute_path: | ||
tuples = [(key.split("/"), pathGet(CONFIG, key))] | ||
else: |
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.
Add error handling for absolute paths
When using absolute paths, pathGet
will raise a KeyError
if the path doesn't exist, but this error is not caught. This could lead to an unhandled exception and poor user experience.
Apply this diff to add proper error handling:
if absolute_path:
- tuples = [(key.split("/"), pathGet(CONFIG, key))]
+ try:
+ tuples = [(key.split("/"), pathGet(CONFIG, key))]
+ except KeyError:
+ console.print(f"[red]Error:[/red] No configuration found at path '/{key}'")
+ exit()
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if absolute_path: | |
tuples = [(key.split("/"), pathGet(CONFIG, key))] | |
else: | |
if absolute_path: | |
try: | |
tuples = [(key.split("/"), pathGet(CONFIG, key))] | |
except KeyError: | |
console.print(f"[red]Error:[/red] No configuration found at path '/{key}'") | |
exit() | |
else: |
#182 contains a superset of functionality compared to this PR. If the other PR is intended to get merged, then this PR can get closed. |
analogously to
$ ovos-config get -k /location/city/name
one can now set values with absolute key paths
$ ovos-config set -k /location/city/name -v Mycity
addresses #180
Summary by CodeRabbit
New Features
set
command in the configuration management tool for improved handling of absolute paths.Bug Fixes