Skip to content

feat: add --json flag support to auth subcommands - #1431

Merged
JackZhao10086 merged 3 commits into
mainfrom
feat/auth_cmd_json
Jun 12, 2026
Merged

feat: add --json flag support to auth subcommands#1431
JackZhao10086 merged 3 commits into
mainfrom
feat/auth_cmd_json

Conversation

@JackZhao10086

@JackZhao10086 JackZhao10086 commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR makes auth subcommands more consistent for machine-readable usage by adding --json compatibility where it previously caused unknown flag errors. It keeps existing output contracts unchanged for status, list, check, and logout, while making auth scopes --json explicitly map to JSON output.

Changes

  • Add compatibility --json flags to auth status, auth list, auth check, and auth logout without changing their existing output behavior
  • Add --json support to auth scopes and map it to --format json
  • Add command parsing tests covering the new --json compatibility behavior across the updated auth subcommands

Test Plan

  • Unit tests pass
  • Manual local verification confirms the lark-cli <domain> <command> flow works as expected

Related Issues

  • None

Summary by CodeRabbit

  • New Features

    • Added a --json option to auth commands (check, logout, list, status, scopes) to emit structured JSON; scopes' --json forces JSON output.
  • Bug Fixes / Behavior

    • auth list and logout now return JSON for configured/not-configured and no-user cases when --json is used; non-JSON behavior preserved.
  • Tests

    • Added tests validating --json handling and JSON vs text outputs across auth commands.

@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a --json boolean flag to auth subcommands (check, logout, list, status, scopes) by adding a JSON field to each options struct; scopes forces Format="json" when set, and logout emits structured JSON for error and success paths. Tests cover flag acceptance and logout output modes.

Changes

JSON Flag Support for Auth Commands

Layer / File(s) Summary
--json flag for check, list, status, logout commands
cmd/auth/check.go, cmd/auth/list.go, cmd/auth/status.go, cmd/auth/logout.go
Adds JSON bool to CheckOptions, ListOptions, StatusOptions, and LogoutOptions and registers a --json boolean flag in each NewCmdAuth* function.
Scopes command with JSON format forcing
cmd/auth/scopes.go
Adds JSON bool to ScopesOptions, replaces the prior --format string flag with a --json boolean, and forces opts.Format = "json" when opts.JSON is set.
Logout command JSON output behavior
cmd/auth/logout.go
When opts.JSON is enabled, authLogoutRun returns structured JSON payloads for not_configured, not_logged_in, and successful logout cases instead of plain-text stderr/stdout messages.
Tests for --json flag acceptance and logout behavior
cmd/auth/auth_test.go, cmd/auth/logout_test.go, cmd/auth/list_test.go
Adds tests verifying --json sets the options field for check/logout/list/status, that --json forces scopes format to "json", and that authLogoutRun emits correct JSON and text outputs across error/success scenarios (with helper and keyring setup).

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

feature

Suggested reviewers

  • liangshuo-1
  • albertnusouo

Poem

🐰 A tiny flag hops in, all bright and true,
Now auth speaks JSON in a neat debut,
From check to logout, list and status too,
Scopes bow to JSON, format set anew,
Tests nudge carrots to prove the hop through.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 24.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding --json flag support to auth subcommands, which is the core purpose of this PR.
Description check ✅ Passed The description includes all required template sections (Summary, Changes, Test Plan, Related Issues) with substantive content addressing the PR's objectives and scope.
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.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/auth_cmd_json

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.

@github-actions github-actions Bot added the size/L Large or sensitive change across domains or core paths label Jun 12, 2026
@codecov

codecov Bot commented Jun 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.86%. Comparing base (76ba6fa) to head (f0b4292).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1431      +/-   ##
==========================================
+ Coverage   72.83%   72.86%   +0.03%     
==========================================
  Files         732      732              
  Lines       69140    69181      +41     
==========================================
+ Hits        50356    50411      +55     
+ Misses      15003    14987      -16     
- Partials     3781     3783       +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown

🚀 PR Preview Install Guide

🧰 CLI update

npm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@f0b42920c07b18cdc034fe26641896a9adfbc5b1

🧩 Skill update

npx skills add larksuite/cli#feat/auth_cmd_json -y -g

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

🧹 Nitpick comments (1)
cmd/auth/logout_test.go (1)

1-147: ⚡ Quick win

Consider adding error-path test for SaveMultiAppConfig failure.

The logout implementation has an error return path when core.SaveMultiAppConfig(multi) fails (see cmd/auth/logout.go Line 88), but there's no test exercising this case. As per coding guidelines, error-path tests should assert typed metadata (category, subtype, cause) via errs.ProblemOf.

💡 Example error-path test structure
func TestAuthLogoutRun_SaveConfigError_ReturnsTypedError(t *testing.T) {
	// Setup: create a scenario where SaveMultiAppConfig will fail
	// (e.g., read-only filesystem, permission error, etc.)
	
	// Assert the error is typed:
	// - Use errs.ProblemOf to check category=internal, subtype=storage
	// - Verify .WithCause(err) preserved the underlying error
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/auth/logout_test.go` around lines 1 - 147, Add a test that forces
core.SaveMultiAppConfig to fail and asserts authLogoutRun returns a typed error:
arrange the environment (set LARKSUITE_CLI_CONFIG_DIR to a temp dir), make
SaveMultiAppConfig fail by making the config path unwritable (e.g., create the
config dir and set its permissions readonly or create a file that blocks
writing), call authLogoutRun(&LogoutOptions{Factory: f, JSON: true}) and capture
the error, then use errs.ProblemOf(err) to assert Category == "internal",
Subtype == "storage" and that Problem.Cause wraps the underlying filesystem
error (preserved via .WithCause); reference the functions
core.SaveMultiAppConfig, authLogoutRun, LogoutOptions and errs.ProblemOf when
locating code to change or tests to add.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/auth/logout_test.go`:
- Around line 1-147: Add a test that forces core.SaveMultiAppConfig to fail and
asserts authLogoutRun returns a typed error: arrange the environment (set
LARKSUITE_CLI_CONFIG_DIR to a temp dir), make SaveMultiAppConfig fail by making
the config path unwritable (e.g., create the config dir and set its permissions
readonly or create a file that blocks writing), call
authLogoutRun(&LogoutOptions{Factory: f, JSON: true}) and capture the error,
then use errs.ProblemOf(err) to assert Category == "internal", Subtype ==
"storage" and that Problem.Cause wraps the underlying filesystem error
(preserved via .WithCause); reference the functions core.SaveMultiAppConfig,
authLogoutRun, LogoutOptions and errs.ProblemOf when locating code to change or
tests to add.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a7f1132a-b646-4c0c-b0a0-da13f332932f

📥 Commits

Reviewing files that changed from the base of the PR and between fa8d094 and a304431.

📒 Files selected for processing (2)
  • cmd/auth/logout.go
  • cmd/auth/logout_test.go

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

🧹 Nitpick comments (1)
cmd/auth/list.go (1)

49-81: ⚖️ Poor tradeoff

Consider unifying the response format in a future breaking-change release.

When --json is used with empty states, the output is an object with ok, users, and reason fields. However, when users exist (line 100), the output is a bare array. Clients must detect and handle both shapes:

  • Empty: {"ok": true, "users": [], "reason": "not_configured"}
  • Populated: [{...}, {...}]

A uniform response shape would simplify client parsing. For example, always wrapping in {"ok": true, "users": [...]} with an optional reason field when empty.

However, changing line 100 now would break existing callers, and the PR explicitly preserves backward compatibility. Consider documenting this inconsistency and addressing it in a coordinated breaking-change release.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/auth/list.go` around lines 49 - 81, The JSON output shape is
inconsistent: empty states use output.PrintJson with {"ok", "users", "reason"}
while the populated branch (where users exist, invoked after
multi.CurrentAppConfig) returns a bare array; to fix, change the populated
branch to emit the same wrapped shape (call output.PrintJson(f.IOStreams.Out,
map[string]interface{}{"ok": true, "users": users}) and include "reason" only
when appropriate), update any tests/examples that expect the bare array, and add
a short note in CLI docs; touch the code paths around opts.JSON handling and the
populated-users response in list.go so both empty and non-empty branches use the
unified response object.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@cmd/auth/list.go`:
- Around line 49-81: The JSON output shape is inconsistent: empty states use
output.PrintJson with {"ok", "users", "reason"} while the populated branch
(where users exist, invoked after multi.CurrentAppConfig) returns a bare array;
to fix, change the populated branch to emit the same wrapped shape (call
output.PrintJson(f.IOStreams.Out, map[string]interface{}{"ok": true, "users":
users}) and include "reason" only when appropriate), update any tests/examples
that expect the bare array, and add a short note in CLI docs; touch the code
paths around opts.JSON handling and the populated-users response in list.go so
both empty and non-empty branches use the unified response object.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5c3a70fd-f18f-4cc5-869f-4698e5be24ff

📥 Commits

Reviewing files that changed from the base of the PR and between a304431 and f0b4292.

📒 Files selected for processing (2)
  • cmd/auth/list.go
  • cmd/auth/list_test.go

@JackZhao10086
JackZhao10086 merged commit 465c789 into main Jun 12, 2026
29 of 31 checks passed
@JackZhao10086
JackZhao10086 deleted the feat/auth_cmd_json branch June 12, 2026 07:04
@coderabbitai coderabbitai Bot mentioned this pull request Jun 12, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large or sensitive change across domains or core paths

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants