gh70 - xts demo#72
Conversation
|
I have read the CLA Document and I hereby sign the CLA zghp seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
There was a problem hiding this comment.
Pull request overview
Adds an xts demo built-in command intended to walk first-time users through alias setup and running a sample command, along with test coverage and README updates.
Changes:
- Adds a
demobuilt-in path inXTS._parse_first_arg()and an interactive_run_demo()flow. - Adds a pytest that exercises the demo flow via monkeypatching and a fake
YamlRunner. - Documents the new
xts democommand in the README.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
src/xts_core/xts.py |
Adds demo built-in handling, interactive demo flow, and a YamlRunner-compatibility fallback. |
test/test_xts_all_cases.py |
Adds an end-to-end-ish test for xts demo and adjusts import path handling. |
README.md |
Documents the new interactive demo command. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # * If not stated otherwise in this file or this component's LICENSE file the | ||
| # * following copyright and licenses apply: | ||
| # * | ||
| # * Copyright 2024 RDK Management | ||
| # * | ||
| # * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # * you may not use this file except in compliance with the License. | ||
|
|
||
| # * You may obtain a copy of the License at |
| alias_name = remaining_args[0] | ||
|
|
||
| if alias_name == 'demo': | ||
| self._run_demo() | ||
| raise SystemExit(0) | ||
|
|
||
| resolved_xts_path = xts_alias.resolve_alias_to_xts_path(alias_name) | ||
|
|
| package_root = Path(__file__).resolve().parents[2] | ||
| example_config = package_root / 'examples' / 'hello_world.xts' | ||
| if example_config.exists(): | ||
| return str(example_config) | ||
|
|
||
| alt_example = Path.cwd() / 'examples' / 'hello_world.xts' | ||
| if alt_example.exists(): | ||
| return str(alt_example) | ||
|
|
||
| error( | ||
| 'Could not locate demo example config. Ensure examples/hello_world.xts exists.' | ||
| ) | ||
|
|
| def _collect_command_paths(self, section: dict, prefix: list[str] | None = None) -> list[list[str]]: | ||
| """Recursively collect leaf command paths from a command section.""" | ||
| prefix = prefix or [] | ||
| paths: list[list[str]] = [] | ||
|
|
||
| for key, value in section.items(): | ||
| if not isinstance(value, dict): | ||
| continue | ||
|
|
||
| if 'command' in value: | ||
| paths.append(prefix + [key]) | ||
|
|
||
| paths.extend(self._collect_command_paths(value, prefix + [key])) | ||
|
|
||
| return paths |
| info('Welcome to the XTS interactive demo!') | ||
| info('This demo will add an alias, show the alias list, and run all example commands.') | ||
| print() |
| help_command = 'xts --alias --help' | ||
| add_command = f'xts --alias --add {example_config_path} --name {alias_name}' | ||
| list_command = 'xts --alias --list' | ||
| run_command = f'xts {alias_name} run hello_world' | ||
| remove_command = f'xts --alias --remove {alias_name}' | ||
|
|
| print() | ||
| info('Section 5: Remove the demo alias.') | ||
| info(f' Command: {remove_command}') | ||
| input('Press Enter to execute this command and continue... ') | ||
| try: | ||
| xts_alias.run_alias_builtin(['--remove', alias_name]) | ||
| except Exception as e: | ||
| error(f'Failed to remove demo alias: {e}') | ||
|
|
||
| print() | ||
| info('Demo finished. You can now add your own aliases with xts --alias --add <path> --name <alias>.') |
| assert 'Command: xts demo-example run hello_world' in output | ||
| assert 'Section 5: Remove the demo alias.' in output | ||
| assert 'Command: xts --alias --remove demo-example' in output | ||
| assert 'Section 6: Refresh the demo alias.' in output | ||
| assert 'Command: xts --alias --refresh demo-example' in output | ||
| assert 'demo-example ->' in output | ||
| assert 'Removed alias: demo-example' in output | ||
| assert 'Demo finished. You can now add your own aliases' in output |
| A new interactive demo command is available to guide first-time users through alias setup and execution: | ||
|
|
||
| ```sh | ||
| xts demo | ||
| ``` | ||
|
|
||
| It will add a sample alias from `examples/hello_world.xts`, list the alias, and execute the example `hello_world` command. | ||
|
|
|
b'## WARNING: A Blackduck scan failure has been waived A prior failure has been upvoted
|
No description provided.