Skip to content

Enable displaying tasks as JSON#165

Open
ryanprior wants to merge 3 commits into
joerdav:mainfrom
ryanprior:ryanprior/json-output
Open

Enable displaying tasks as JSON#165
ryanprior wants to merge 3 commits into
joerdav:mainfrom
ryanprior:ryanprior/json-output

Conversation

@ryanprior
Copy link
Copy Markdown
Contributor

Fixes #149

Context

In my Emacs integration for xc, I would like to prompt the user for task inputs when they're required, but it's not as straightforward to enumerate the task inputs as I'd like. This PR adds a facility to display the JSON representation for the parsed task data structure, which is ideal for tool integrations like this.

In this PR

  • new method Task.DisplayJSON in models package
  • new flag -output, defaulting to "markdown" but also accepting "json", for the user to control how to display a task (with -display)
  • updated documentation and tests

Next steps

Now that this is ready for review, I'll start work to use this data in the Emacs integration to enumerate task inputs and prompt for them interactively.

Special thanks

Appreciation to @jgarte for pair programming with me on this enhancement. Thank you Jorge!

@ryanprior ryanprior requested a review from joerdav as a code owner February 6, 2026 21:17
@ryanprior ryanprior force-pushed the ryanprior/json-output branch from 17e6d50 to c949995 Compare February 6, 2026 21:21
ryanprior and others added 3 commits February 6, 2026 21:48
Uses encoding/json package to write a task to the target writer as JSON.

Co-authored-by: jgart <jgart@dismail.de>
Co-authored-by: jgart <jgart@dismail.de>
@ryanprior ryanprior force-pushed the ryanprior/json-output branch from c949995 to 874bdfd Compare February 6, 2026 21:49
@ryanprior
Copy link
Copy Markdown
Contributor Author

Interesting wrinkle: the error case for the JSON display function wasn't covered in testing, which caused test coverage overall to drop and held up the PR. I dug into the JSON docs in golang to find a value that would trigger the error case so I could account for that in testing, and found that none of the types in the Task struct can accept un-marshalable values. (I tried typecasting and that just resulted in weird, but valid, values.) So I removed the error handling code and left a comment in its place 🙃

Here's the code coverage report that helped me understand that was what was causing code coverage to drop: https://coveralls.io/builds/77696075/source?filename=models%2Fmodels.go#L63

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.

Command to provide machine-readable information about task inputs

1 participant