Skip to content

Keep dashed CLI flags off the TUI - #40

Merged
kgrizz-git merged 1 commit into
mainfrom
fix/tui-only-on-bare-argv
Nov 14, 2026
Merged

kgrizz-git merged 1 commit into
mainfrom
fix/tui-only-on-bare-argv

Conversation

@kgrizz-git

@kgrizz-git kgrizz-git commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Launch the Textual TUI only for a bare github-usage when both stdin and stdout are TTYs. Dashed arguments such as --export, --no-interactive, and -v stay on the CLI.
  • scripts/check runs unittest with stdin from /dev/null and a 180s kill -9 cap, so a routing regression cannot hang the harness. The coverage discover gets the same stdin redirect.
  • ./start.sh -v is unchanged: the shell script already maps -v to --version before Python routing. Version stays 0.1.0; the note is under [Unreleased].

Test plan

  • tests.test_gui_models covers dashed argv on a forced TTY (run_tui not called, argv preserved) and still covers the bare-TTY launch.
  • On a drained PTY, test_export_does_not_call_user_when_session_returns_data exits ok instead of drawing the TUI.
  • On a drained PTY, github-usage --export json --no-interactive with an empty HOME, no token env, and PATH=/usr/bin:/bin exits 1 with "No GitHub token found" and does not draw the TUI.
  • python -m github_usage </dev/null prints help and exits 0.
  • Full unittest discover with stdin from /dev/null passes (OK (skipped=2)).
  • Pre-push scripts/check, coverage, and complexity gates passed.

A full discover attached to a PTY still blocks later in test_token_positional_only, which calls input() for an export format when stdin is a TTY and --no-interactive is absent. That prompt is separate from the TUI hang. scripts/check does not hit it because stdin is /dev/null.

Made with Cursor

Summary by Sourcery

Restrict TUI startup to bare interactive invocations and make automated checks resilient to interactive hangs.

Bug Fixes:

  • Prevent dashed CLI arguments from launching the Textual TUI when running in a terminal, keeping commands such as export, non-interactive mode, and version on the CLI path.
  • Harden test and coverage checks against hanging on interactive stdin by redirecting stdin and enforcing a timeout.

Documentation:

  • Document the CLI routing fix in the unreleased changelog.

Tests:

  • Add coverage verifying that dashed arguments bypass the TUI while bare terminal invocation still launches it.

Summary by CodeRabbit

  • Bug Fixes
    • CLI arguments such as --export, --no-interactive, and -v now stay in CLI mode when run in a terminal. Running github-usage alone in a terminal continues to launch the interactive app.
  • Chores
    • Unit tests now stop with a clear failure if they exceed the 180-second time limit.

Bare github-usage still opens the Textual app. scripts/check now feeds unittest stdin from /dev/null and kills a run that exceeds 180s, so a routing regression cannot hang the harness.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sourcery-ai

sourcery-ai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Restrict automatic TUI launch to bare invocations in a TTY, leaving dashed arguments for CLI handling.

  • src/github_usage/cli_gui.py L79

Configuration

Make the check and coverage harnesses run with stdin redirected so tests cannot hang on terminal input.

  • scripts/check L11-34
  • scripts/coverage-check L18

Documentation

Record the CLI routing change and its behavior in the changelog.

  • CHANGELOG.md L13

Tests

Cover dashed arguments on a TTY and verify they bypass the TUI while preserving argv.

  • tests/test_gui_models.py L67-79

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The CLI enters the TUI only when arguments are empty and both standard input and output are TTYs. The unit-test script adds a 180-second timeout and process cleanup. The coverage script redirects test-discovery input from standard input to /dev/null.

Changes: CLI Argument Routing

Layer / File(s) Summary
TUI routing condition and validation
src/github_usage/cli_gui.py, tests/test_gui_models.py, CHANGELOG.md
The TUI launch condition now requires empty arguments. A test checks that dashed arguments on a TTY remain unhandled and do not launch the TUI. The changelog records the routing behavior and the unchanged ./start.sh -v mapping.

Test Script Execution

Layer / File(s) Summary
Test process and input handling
scripts/check, scripts/coverage-check
The unit-test script runs tests in the background with a 180-second timeout and cleans up tracked processes. The coverage script redirects test-discovery input from standard input to /dev/null.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 985d4

Dashed CLI flags now stay in CLI mode in a terminal, and only a bare invocation opens the TUI. The remaining changes affect test scripts only. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "Keep dashed CLI flags off the TUI" matches the main change. The PR routes dashed arguments (such as --export, --no-interactive, and -v) to the CLI path. It launches the Textual TUI only for…
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.
Full details: Title check

Explanation

The title "Keep dashed CLI flags off the TUI" matches the main change. The PR routes dashed arguments (such as --export, --no-interactive, and -v) to the CLI path. It launches the Textual TUI only for a bare github-usage invocation when stdin and stdout are TTYs. The title is specific and short, and it does not use vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 567a0b8 and 985d4d9.

Files selected for processing: 5

  • CHANGELOG.md
  • scripts/check
  • scripts/coverage-check
  • src/github_usage/cli_gui.py
  • tests/test_gui_models.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@deepsource-io

deepsource-io Bot commented Nov 14, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 567a0b8...985d4d9 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Secrets Nov 14, 2026 9:09p.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@sonarqubecloud

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

The PR keeps dashed arguments on the CLI and reserves automatic TUI launch for a bare command with both stdin and stdout attached to a terminal.

  • The terminal interface opens only when github-usage has no arguments.
  • Test runs get closed stdin, and the main check stops them after 180 seconds.

Reviews (1) · Last reviewed commit: "Keep dashed CLI arguments on the CLI whe..." · Reviewed by Greptile

@kgrizz-git

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@kgrizz-git
kgrizz-git merged commit 1f6f15f into main Nov 14, 2026
17 checks passed
@kgrizz-git
kgrizz-git deleted the fix/tui-only-on-bare-argv branch November 14, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant