Skip to content

feat: add machine-friendly output modes to token create#786

Open
inickt wants to merge 3 commits intolivekit:mainfrom
inickt:token-create-scripting-output
Open

feat: add machine-friendly output modes to token create#786
inickt wants to merge 3 commits intolivekit:mainfrom
inickt:token-create-scripting-output

Conversation

@inickt
Copy link
Contributor

@inickt inickt commented Mar 9, 2026

Adds scripting-friendly output modes to token generation:

  • supports --json and --token-only for both lk token create and deprecated lk create-token
  • keeps existing human-readable default output unchanged
  • validates conflicting flags (--json with --token-only)
  • adds tests for mode resolution and output behavior

Example:
lk token create --list --json | jq -r '.access_token' (also needs #785)

Other options would be:

  • alter the default lk token create command to send more information to stderr instead, so the --token-only flag isn't needed.
  • detect if we are in a pipe, and automatically suppress output in that case

I thought those were more involved changes so opted for this

Copy link
Member

@rektdeckard rektdeckard left a comment

Choose a reason for hiding this comment

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

Just a few comments, but overall idea is sound!

cmd/lk/token.go Outdated
if dur, err := time.ParseDuration(validFor); err == nil {
fmt.Println("valid for (mins): ", int(dur/time.Minute))
if outputMode == tokenOutputModeHuman {
fmt.Println("valid for (mins): ", int(dur/time.Minute))
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

Copy link
Member

Choose a reason for hiding this comment

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

Note to self: our homebrew formula currently has a smoketest that checks stdOut for several commands; this will need to be updated in next release.

@inickt
Copy link
Contributor Author

inickt commented Mar 12, 2026

@rektdeckard I think I got this cleaned up, not a go dev by any means so please keep me in check if I have any funky patterns going on

@inickt inickt requested a review from rektdeckard March 12, 2026 02:11
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