Skip to content

Add text output mode for auth token#4903

Merged
simonfaltum merged 3 commits intomainfrom
simonfaltum/auth-token-text-output
Apr 7, 2026
Merged

Add text output mode for auth token#4903
simonfaltum merged 3 commits intomainfrom
simonfaltum/auth-token-text-output

Conversation

@simonfaltum
Copy link
Copy Markdown
Member

Why

auth token always outputs JSON, ignoring the --output flag. If you want to pipe just the token string into another tool, you have to parse JSON. That's unnecessary friction for a common scripting pattern.

Changes

auth token now respects --output text when explicitly set, outputting just the access token string (with a trailing newline) suitable for piping. JSON remains the default for backward compatibility.

Only honors the explicit --output text flag, not implicit text mode (e.g. from DATABRICKS_OUTPUT_FORMAT), so existing scripts that parse JSON output won't break.

Also fixes discarded write errors (_, _ replaced with proper error returns).

Test plan

  • Unit tests for default (JSON), explicit --output json, and --output text modes
  • Existing cmd/auth tests pass

auth token now respects --output text when explicitly set, outputting
just the access token string suitable for piping. JSON remains the
default for backward compatibility.

Also returns write errors instead of discarding them.

Co-authored-by: Isaac
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 6, 2026

Suggested reviewers

Based on git history of the changed files, these people are best suited to review:

Confidence: low

Eligible reviewers

Based on CODEOWNERS, these people or teams could also review:

@andrewnester, @anton-107, @denik, @shreyas-goenka

Suggestions based on git history of 2 changed files (2 scored). See CODEOWNERS for path-specific ownership rules.

Copy link
Copy Markdown
Contributor

@renaudhartert-db renaudhartert-db left a comment

Choose a reason for hiding this comment

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

LGTM assuming resolution of the open comments.

Address review feedback:
- writeTokenOutput now takes (io.Writer, *oauth2.Token, bool) instead of
  *cobra.Command, making it trivial to test without Cobra machinery
- Replace complex command-level test with direct unit test of
  writeTokenOutput that compares exact output strings
- Remove unused cobra and flags imports from test file

Co-authored-by: Isaac
@simonfaltum
Copy link
Copy Markdown
Member Author

Addressed all three comments in c12e422.

writeTokenOutput now takes (io.Writer, *oauth2.Token, bool) instead of *cobra.Command, so it's fully decoupled from Cobra. The flag-checking logic stays in the caller.

Replaced the command-level test with a simple unit test that calls writeTokenOutput directly and compares exact output strings. No Cobra machinery needed.

@simonfaltum simonfaltum added this pull request to the merge queue Apr 7, 2026
Merged via the queue into main with commit da3daf5 Apr 7, 2026
17 checks passed
@simonfaltum simonfaltum deleted the simonfaltum/auth-token-text-output branch April 7, 2026 10:48
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