🎨 Palette: Improve CLI UX with graceful exit and cleaner help#141
🎨 Palette: Improve CLI UX with graceful exit and cleaner help#141
Conversation
- Wrap interactive prompts in `try...except KeyboardInterrupt` to prevent tracebacks on cancellation. - Remove duplicate `render_progress_bar` function definition to clean up code. - Add usage example to `--help` output via `argparse` epilog. Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
|
Merging to
|
Summary of ChangesHello @abhimehro, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the user experience of the CLI tool by addressing common usability issues. It ensures that interactive sessions can be gracefully interrupted without error messages and provides clearer guidance for command-line arguments, making the tool more robust and intuitive for users. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
| "Invalid ID(s) or URL(s). Must be a valid Profile ID or a Control D Profile URL. Comma-separate for multiple.", | ||
| ) | ||
| profile_ids = [ | ||
| extract_profile_id(p) for p in p_input.split(",") if p.strip() |
Check warning
Code scanning / Pylint (reported by Codacy)
Line too long (143/100) Warning
| print( | ||
| f"{Colors.CYAN} You can generate one at: https://controld.com/account/manage-account{Colors.ENDC}" | ||
| ) | ||
| if not TOKEN: |
Check warning
Code scanning / Pylint (reported by Codacy)
Missing function docstring Warning
| t_input = get_validated_input( | ||
| f"{Colors.BOLD}Enter Control D API Token:{Colors.ENDC} ", | ||
| lambda x: len(x) > 8, | ||
| "Token seems too short. Please check your API token.", |
Check warning
Code scanning / Pylint (reported by Codacy)
Line too long (127/100) Warning
There was a problem hiding this comment.
Pull request overview
This PR refines the CLI UX by removing a duplicate progress-bar implementation, improving the help text, and handling Ctrl+C more gracefully during interactive configuration prompts.
Changes:
- Remove the older duplicate
render_progress_barhelper, leaving a single, documented implementation. - Enhance the CLI argument parser with an
epilogexample to clarify typical usage. - Wrap the interactive configuration prompts in
main()with atry/except KeyboardInterruptto print a friendly cancellation message and exit with code 130 instead of showing a traceback, and add a UX journal entry under.Jules/.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
main.py |
Cleans up duplicate progress bar definition, adds example usage to parse_args(), and introduces a KeyboardInterrupt handler for interactive prompts to provide a graceful cancel UX and exit code 130. |
.Jules/palette.md |
Adds a UX/Accessibility “journal” documenting the learning about handling Ctrl+C gracefully in CLI tools. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try: | ||
| if not args.dry_run and sys.stdin.isatty(): | ||
| if not profile_ids: | ||
| print(f"{Colors.CYAN}ℹ Profile ID is missing.{Colors.ENDC}") | ||
| print( | ||
| f"{Colors.CYAN} You can find this in the URL of your profile in the Control D Dashboard (or just paste the URL).{Colors.ENDC}" | ||
| ) | ||
|
|
||
| def validate_profile_input(value: str) -> bool: | ||
| ids = [extract_profile_id(p) for p in value.split(",") if p.strip()] | ||
| return bool(ids) and all( | ||
| validate_profile_id(pid, log_errors=False) for pid in ids | ||
| ) | ||
|
|
||
| def validate_profile_input(value: str) -> bool: | ||
| ids = [extract_profile_id(p) for p in value.split(",") if p.strip()] | ||
| return bool(ids) and all( | ||
| validate_profile_id(pid, log_errors=False) for pid in ids | ||
| p_input = get_validated_input( | ||
| f"{Colors.BOLD}Enter Control D Profile ID:{Colors.ENDC} ", | ||
| validate_profile_input, | ||
| "Invalid ID(s) or URL(s). Must be a valid Profile ID or a Control D Profile URL. Comma-separate for multiple.", | ||
| ) | ||
| profile_ids = [ | ||
| extract_profile_id(p) for p in p_input.split(",") if p.strip() | ||
| ] | ||
|
|
||
| p_input = get_validated_input( | ||
| f"{Colors.BOLD}Enter Control D Profile ID:{Colors.ENDC} ", | ||
| validate_profile_input, | ||
| "Invalid ID(s) or URL(s). Must be a valid Profile ID or a Control D Profile URL. Comma-separate for multiple.", | ||
| ) | ||
| profile_ids = [ | ||
| extract_profile_id(p) for p in p_input.split(",") if p.strip() | ||
| ] | ||
|
|
||
| if not TOKEN: | ||
| print(f"{Colors.CYAN}ℹ API Token is missing.{Colors.ENDC}") | ||
| print( | ||
| f"{Colors.CYAN} You can generate one at: https://controld.com/account/manage-account{Colors.ENDC}" | ||
| ) | ||
| if not TOKEN: | ||
| print(f"{Colors.CYAN}ℹ API Token is missing.{Colors.ENDC}") | ||
| print( | ||
| f"{Colors.CYAN} You can generate one at: https://controld.com/account/manage-account{Colors.ENDC}" | ||
| ) | ||
|
|
||
| t_input = get_validated_input( | ||
| f"{Colors.BOLD}Enter Control D API Token:{Colors.ENDC} ", | ||
| lambda x: len(x) > 8, | ||
| "Token seems too short. Please check your API token.", | ||
| is_password=True, | ||
| ) | ||
| TOKEN = t_input | ||
| t_input = get_validated_input( | ||
| f"{Colors.BOLD}Enter Control D API Token:{Colors.ENDC} ", | ||
| lambda x: len(x) > 8, | ||
| "Token seems too short. Please check your API token.", | ||
| is_password=True, | ||
| ) | ||
| TOKEN = t_input | ||
| except KeyboardInterrupt: | ||
| sys.stderr.write( | ||
| f"\n{Colors.WARNING}⚠️ Sync cancelled by user.{Colors.ENDC}\n" | ||
| ) | ||
| exit(130) |
There was a problem hiding this comment.
The new KeyboardInterrupt handler around the interactive prompts (lines 1226–1266) introduces user-visible behavior (exit code 130 and a specific warning message to stderr) but there are no tests covering this path, even though other interactive CLI behaviors in main() are well covered in test_main.py. Consider adding a test that simulates a KeyboardInterrupt during get_validated_input (e.g., via a side-effect on input/getpass) and asserts that main() exits with code 130 and emits the expected "Sync cancelled by user" message to stderr, to prevent regressions in this UX-critical flow.
There was a problem hiding this comment.
Code Review
This pull request enhances the CLI tool's user experience by gracefully handling Ctrl+C during interactive prompts, adding a usage example to the --help output, and removing a redundant function. The changes are well-implemented and do not introduce any security vulnerabilities. There is one suggestion to improve the robustness of the exit handling.
| sys.stderr.write( | ||
| f"\n{Colors.WARNING}⚠️ Sync cancelled by user.{Colors.ENDC}\n" | ||
| ) | ||
| exit(130) |
There was a problem hiding this comment.
For better portability and explicitness, it's recommended to use sys.exit() instead of the built-in exit(). The exit() function is part of the site module and is primarily intended for use in the interactive interpreter; it may not be available in all Python environments (e.g., when running with the -S flag). Since sys is already imported, using sys.exit() is a more robust choice for scripts.
| exit(130) | |
| sys.exit(130) |
…itization, add dry-run plan details Incorporates the best changes from 36 Jules PRs, addressing review feedback: Bolt (Performance) - from PR #173: - Pre-compile PROFILE_ID_PATTERN and RULE_PATTERN at module level - Use compiled patterns in is_valid_profile_id_format, validate_profile_id, and is_valid_rule - Supersedes PRs: #140, #143, #152, #155, #158, #161, #167, #170, #173 Sentinel (Security) - from PR #172 with review feedback: - Enhance sanitize_for_log to redact Basic Auth credentials in URLs - Redact sensitive query parameters (token, key, secret, password, etc.) - Handle fragment separators (#) per Gemini Code Assist review - Use [^&#\s]* pattern per Copilot reviewer suggestion - Update docstring per reviewer suggestion - Supersedes PRs: #142, #145, #148, #151, #154, #157, #160, #169, #172 Palette (UX) - from PR #174 with lint fixes: - Add print_plan_details function for dry-run visibility - Fix duplicate render_progress_bar definition bug - Supersedes PRs: #139, #141, #144, #147, #150, #153, #156, #159, #162, #165, #168, #171, #174 Also: #146, #149, #164 (parallel folder deletion) and #166 (auto-fix .env perms) are independent features not consolidated here. Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
…itization, add dry-run plan details Incorporates the best changes from 36 Jules PRs, addressing review feedback: Bolt (Performance) - from PR #173: - Pre-compile PROFILE_ID_PATTERN and RULE_PATTERN at module level - Use compiled patterns in is_valid_profile_id_format, validate_profile_id, and is_valid_rule - Supersedes PRs: #140, #143, #152, #155, #158, #161, #167, #170, #173 Sentinel (Security) - from PR #172 with review feedback: - Enhance sanitize_for_log to redact Basic Auth credentials in URLs - Redact sensitive query parameters (token, key, secret, password, etc.) - Handle fragment separators (#) per Gemini Code Assist review - Use [^&#\s]* pattern per Copilot reviewer suggestion - Update docstring per reviewer suggestion - Supersedes PRs: #142, #145, #148, #151, #154, #157, #160, #169, #172 Palette (UX) - from PR #174 with lint fixes: - Add print_plan_details function for dry-run visibility - Fix duplicate render_progress_bar definition bug - Supersedes PRs: #139, #141, #144, #147, #150, #153, #156, #159, #162, #165, #168, #171, #174 Also: #146, #149, #164 (parallel folder deletion) and #166 (auto-fix .env perms) are independent features not consolidated here. Co-authored-by: abhimehro <84992105+abhimehro@users.noreply.github.com>
This PR improves the user experience of the CLI tool by handling
Ctrl+Cgracefully during interactive prompts, preventing ugly traceback errors. It also adds a helpful usage example to the help output and removes a duplicate function definition.PR created automatically by Jules for task 14962804680975856503 started by @abhimehro