Skip to content

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

Open
inickt wants to merge 1 commit intolivekit:mainfrom
inickt:token-create-scripting-output
Open

feat: add machine-friendly output modes to token create#786
inickt wants to merge 1 commit 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!

Comment on lines +66 to +67
jsonFlag,
tokenOnlyFlag,
Copy link
Member

Choose a reason for hiding this comment

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

Please use MutuallyExclusiveFlags for these rather than implementing the check yourself

participant = util.ExpandTemplate("participant-%x")
fmt.Printf("Using generated participant identity [%s]\n", util.Accented(participant))
if outputMode == tokenOutputModeHuman {
fmt.Printf("Using generated participant identity [%s]\n", util.Accented(participant))
Copy link
Member

Choose a reason for hiding this comment

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

While you're here, let's print things like this to stdErr as well.

room = util.ExpandTemplate("room-%t")
fmt.Printf("Using generated room name [%s]\n", util.Accented(room))
if outputMode == tokenOutputModeHuman {
fmt.Printf("Using generated room name [%s]\n", util.Accented(room))
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

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.

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