Skip to content

Added CLI Support#11

Open
CyrixJD115 wants to merge 4 commits intoDedInc:mainfrom
CyrixJD115:main
Open

Added CLI Support#11
CyrixJD115 wants to merge 4 commits intoDedInc:mainfrom
CyrixJD115:main

Conversation

@CyrixJD115
Copy link
Copy Markdown

@CyrixJD115 CyrixJD115 commented Apr 9, 2026

Added CLI for easy command-line execution and scripting.

Summary by CodeRabbit

  • New Features

    • Added a command-line interface for image/video generation with model, aspect, output (text/json/urls), download, and verbose options.
    • Package now installs a runnable "bingart" console command.
    • Cookie auth supports auto-detection and interactive prompts; explicit exit codes for auth/prompt errors.
  • Documentation

    • README refocused on CLI: new Installation, Usage, flags, examples, download and authentication guidance; removed Python "Complete Example".
  • Chores

    • Version bumped to 1.5.1.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 9, 2026

Warning

Rate limit exceeded

@CyrixJD115 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 12 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 8 minutes and 12 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1eb3caba-1623-43f3-8b3f-962bd16bee92

📥 Commits

Reviewing files that changed from the base of the PR and between 59bed86 and a38a4d5.

📒 Files selected for processing (2)
  • README.MD
  • bingart/cli.py
📝 Walkthrough

Walkthrough

Adds a full command-line interface to the bingart package, an executable entrypoint script, a package version export, packaging entry-point registration, and a README refocused on CLI usage and examples.

Changes

Cohort / File(s) Summary
CLI Implementation
bingart/cli.py
New CLI module implementing argument parsing, model/aspect mapping, cookie resolution with precedence/interactive prompt, async runtime, output formatters (`text
Entrypoint Script
bingart.py
New executable script that dynamically loads the local bingart package and invokes bingart.cli:main.
Package Init & Packaging
bingart/__init__.py, setup.py
Added __version__ = "1.5.1" and exported it in __all__; setup.py now reads README.MD and registers a console_scripts entry point bingart = bingart.cli:main.
Documentation
README.MD
Reworked README to lead with CLI-focused introduction, added Installation and comprehensive CLI Usage (flags, models/aspects, auth resolution, exit codes, examples), removed prior Python “Complete Example”, minor example tweaks and punctuation change.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as CLI Parser
    participant Auth as Cookie Resolver
    participant Client as BingArt Client
    participant API as Remote API
    participant DL as Downloader

    User->>CLI: run `bingart` with args
    CLI->>CLI: parse args, map model/aspect, set output/download flags
    CLI->>Auth: resolve_cookie(args)
    Auth->>Auth: check --cookie, --auto, env, prompt
    Auth-->>CLI: return cookie or auto mode
    CLI->>Client: create client (auth cookie or auto)
    CLI->>Client: generate(prompt, model, aspect, content_type)
    Client->>API: submit generation request
    API-->>Client: return result (images/video URLs)
    Client-->>CLI: deliver result
    CLI->>CLI: format output (text/json/urls)
    CLI-->>User: print output
    alt --download set
        CLI->>DL: download_results(result, dest_dir)
        DL->>DL: download_file each URL (urllib -> curl_cffi fallback)
        DL-->>User: per-file success/failure
    end
    CLI-->>User: exit with status code
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A tiny script hops into the night,
Prompts and cookies shining bright,
Arguments parsed, downloads in tow,
BingArt now runs where terminals glow.

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Added CLI Support' directly and clearly summarizes the main change in the pull request, which is the introduction of a command-line interface to the bingart package.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@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.

Actionable comments posted: 2

🧹 Nitpick comments (1)
bingart/cli.py (1)

78-94: Unnecessary mutually exclusive groups for single arguments.

The model_group and aspect_group each contain only one argument, making the mutually exclusive wrapper unnecessary. These could be simplified to direct parser.add_argument() calls.

♻️ Suggested simplification
-    model_group = parser.add_mutually_exclusive_group()
-    model_group.add_argument(
+    parser.add_argument(
         "-m",
         "--model",
         choices=list(MODEL_MAP.keys()),
         default="dalle",
         help="AI model to use (default: dalle).",
     )

-    aspect_group = parser.add_mutually_exclusive_group()
-    aspect_group.add_argument(
+    parser.add_argument(
         "-a",
         "--aspect",
         choices=list(ASPECT_MAP.keys()),
         default="square",
         help="Aspect ratio (default: square).",
     )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bingart/cli.py` around lines 78 - 94, The parser uses unnecessary mutually
exclusive groups model_group and aspect_group each wrapping a single
add_argument; remove the calls to parser.add_mutually_exclusive_group() and
register the options directly via parser.add_argument for --model and --aspect
(keeping choices=list(MODEL_MAP.keys())/list(ASPECT_MAP.keys()), defaults
"dalle" and "square", and the same help texts) so you no longer reference
model_group or aspect_group and simplify the CLI setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bingart/cli.py`:
- Around line 165-182: The async function download_file currently calls blocking
APIs (urllib.request.urlretrieve and curl_cffi.requests.get) and silences all
exceptions, so convert the blocking calls to run in the event loop's executor
(e.g., loop.run_in_executor) or replace them with an async HTTP client (aiohttp)
inside download_file; capture exceptions instead of using bare except: pass and
log debug-level details (when verbose or logger is available) including the URL
and exception info to aid troubleshooting; update the branches that use
urllib.request.urlretrieve and the curl_cffi get call accordingly and ensure the
function still returns True/False based on success.

In `@README.MD`:
- Around line 33-37: Update the README clone command to use the main repository
URL instead of the contributor's fork: replace the git clone URL
`https://github.com/CyrixJD115/bingart.git` with
`https://github.com/DedInc/bingart.git` in the README.MD example so users clone
the canonical repo (the surrounding commands `cd bingart` and `python bingart.py
--help` remain unchanged).

---

Nitpick comments:
In `@bingart/cli.py`:
- Around line 78-94: The parser uses unnecessary mutually exclusive groups
model_group and aspect_group each wrapping a single add_argument; remove the
calls to parser.add_mutually_exclusive_group() and register the options directly
via parser.add_argument for --model and --aspect (keeping
choices=list(MODEL_MAP.keys())/list(ASPECT_MAP.keys()), defaults "dalle" and
"square", and the same help texts) so you no longer reference model_group or
aspect_group and simplify the CLI setup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dc4638ad-ee48-497c-b1e1-2624fd625ae1

📥 Commits

Reviewing files that changed from the base of the PR and between 3a0c26e and fc474a1.

📒 Files selected for processing (5)
  • README.MD
  • bingart.py
  • bingart/__init__.py
  • bingart/cli.py
  • setup.py

Comment thread bingart/cli.py
Comment thread README.MD
…mplify arg parser

- Run urllib and curl_cffi blocking calls in run_in_executor to avoid
  blocking the event loop in download_file
- Log debug-level details on download failure instead of silently
  swallowing exceptions
- Update README clone URL to point to canonical DedInc/bingart repo
- Remove unnecessary mutually exclusive groups for --model and --aspect
Copy link
Copy Markdown

@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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
bingart/cli.py (1)

275-280: Avoid stacking duplicate log handlers across repeated run() calls.

If run(args) is invoked multiple times in one process, this adds a new handler each time and duplicates logs.

♻️ Suggested guard
     if args.verbose:
         logger.setLevel(logging.DEBUG)
-        handler = logging.StreamHandler(sys.stderr)
-        handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
-        logger.addHandler(handler)
+        if not logger.handlers:
+            handler = logging.StreamHandler(sys.stderr)
+            handler.setFormatter(logging.Formatter("%(levelname)s: %(message)s"))
+            logger.addHandler(handler)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@bingart/cli.py` around lines 275 - 280, The verbose logging branch in run
(conditional on args.verbose) unconditionally creates and adds a StreamHandler
to logger, causing duplicate handlers and repeated log output when run() is
called multiple times; update the run function to check for an existing
equivalent handler before adding (e.g., inspect logger.handlers for a
StreamHandler with the same formatter/level) or clear/add handlers idempotently
so logger.addHandler(handler) only runs once, ensuring the logging setup
(handler creation, formatter assignment, and logger.setLevel/logging.debug call)
is guarded against duplicate registration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@bingart/cli.py`:
- Around line 163-172: download_file currently passes the raw URL into
urllib.request.urlretrieve which allows non-http(s) schemes; before calling
loop.run_in_executor (and before urlretrieve), parse the URL (e.g.,
urllib.parse.urlparse) and explicitly check that parsed.scheme is "http" or
"https", and if not, raise a ValueError or return an error/log via the existing
logger; ensure the validation happens early in the download_file function
(before the lambda using urllib.request.urlretrieve) so only allowed schemes
reach urlretrieve.

In `@README.MD`:
- Around line 46-47: Update the primary CLI examples in README.MD to use the
installed entrypoint `bingart` instead of `python bingart.py` (e.g., change
`python bingart.py "sunset over mountains" -c YOUR_U_COOKIE` to `bingart "sunset
over mountains" -c YOUR_U_COOKIE`), and keep the `python bingart.py ...` form
only in the "From Source (Portable)" section; apply this replacement
consistently for all occurrences referenced (examples around the shown snippets
and the ranges noted).
- Line 63: Several fenced code blocks lack language identifiers causing
markdownlint MD040; update each triple-backtick block that contains plain text
examples (e.g., the block starting with "usage: bingart [-h]...", blocks showing
"Model: DALLE", and the block with "https://th.bing.com/th/id/OIG...") to
include a language tag such as ```text (or ```bash for CLI examples) so every
fenced code block has an explicit language identifier.

---

Nitpick comments:
In `@bingart/cli.py`:
- Around line 275-280: The verbose logging branch in run (conditional on
args.verbose) unconditionally creates and adds a StreamHandler to logger,
causing duplicate handlers and repeated log output when run() is called multiple
times; update the run function to check for an existing equivalent handler
before adding (e.g., inspect logger.handlers for a StreamHandler with the same
formatter/level) or clear/add handlers idempotently so
logger.addHandler(handler) only runs once, ensuring the logging setup (handler
creation, formatter assignment, and logger.setLevel/logging.debug call) is
guarded against duplicate registration.
🪄 Autofix (Beta)

❌ Autofix failed (check again to retry)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0d337ed5-1452-47c4-81ed-75745682c40f

📥 Commits

Reviewing files that changed from the base of the PR and between fc474a1 and 59bed86.

📒 Files selected for processing (2)
  • README.MD
  • bingart/cli.py

Comment thread bingart/cli.py
Comment thread README.MD Outdated
Comment thread README.MD Outdated
…e blocks, guard duplicate handler

- Validate URL scheme (http/https only) before download to prevent
  non-http URLs reaching urllib
- Replace python bingart.py with bingart entrypoint in all CLI examples
  outside the From Source section
- Add text language identifiers to bare fenced code blocks in README
- Guard StreamHandler registration against duplicate accumulation in
  run()
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 10, 2026

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Autofix skipped. No unresolved CodeRabbit review comments with fix instructions found.

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