Skip to content

feat(upload): --json output + fix(push): tags sent as array - #13

Open
HarishTeens wants to merge 2 commits into
simplynadaf:mainfrom
HarishTeens:feat/json-output-and-tags-fix
Open

HarishTeens wants to merge 2 commits into
simplynadaf:mainfrom
HarishTeens:feat/json-output-and-tags-fix

Conversation

@HarishTeens

Copy link
Copy Markdown
Contributor

Follow-up to #12. Two changes.

1. devpub upload --json (the flag you suggested)

Machine-readable output for scripting:

$ devpub upload cover.png diagram.png --json
{
  "uploaded": [
    { "file": "cover.png",   "path": "cover.png",   "url": "https://dev-to-uploads.s3.../a.png" },
    { "file": "diagram.png", "path": "diagram.png", "url": "https://dev-to-uploads.s3.../b.png" }
  ],
  "failed": []
}

Design points:

  • stdout stays pure JSON. All human progress (Uploaded: …, the summary) goes to stderr in --json mode, so devpub upload *.png --json | jq just works.
  • Exit code. The command now exits non-zero if any file failed — in every mode, not just --json. A CLI that half-fails silently returning 0 is a footgun for scripts; failed is also surfaced in the JSON.
  • Mutually exclusive with --markdown (raises a UsageError).

2. fix(push): tags were being dropped

Separate bug I hit while using the tool: article_to_api_payload parsed frontmatter tags into a list and then re-joined them into a comma string before sending. Dev.to accepts a string tags field but silently yields an empty tag_list, so every devpub push published the article with no tags. Now it sends the array (reusing _parse_tags) and omits the field when empty. Updated the one existing test that asserted the buggy string form, plus added cases (list, comma-string, empties).

You'd asked to bundle these; happy to split into two PRs if you'd prefer to review/merge them independently.

Verification

ruff check src/ tests/   # clean
pytest                   # 137 passed

New tests: tests/test_cli_upload.py (JSON purity on stdout, failure→exit 1, mutual exclusion) and tag cases in tests/test_articles.py.

Bumps to 0.4.0 (new flag = minor; the tags change is a bugfix in the same release).

🤖 Generated with Claude Code

harishr-as and others added 2 commits August 28, 2026 06:33
article_to_api_payload joined the parsed tag list back into a comma string.
Dev.to accepts that field but silently produces an empty tag_list, so every
push published the article with no tags. Send the list directly (reusing
_parse_tags), and omit the field when empty.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Prints a machine-readable result object ({uploaded, failed}) to stdout for
scripting; human progress goes to stderr so stdout stays pure JSON, and the
command exits non-zero if any file failed. Mutually exclusive with --markdown.

Bumps to 0.4.0.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

2 participants