Ghost v2.0.0 Single Query
Yesterday I release the first version of the major refactor for Ghost. This includes just a single, root command to run a prompt against the /generate endpoint.

Exit Codes#
I decided I wanted to be able to tie errors to proper exit codes so created a package that defined a new error type. Why? I’m just like that.

This uses a list of constants.

You can just wrap the exit code with the error.

Then unwrap.

I’ll probably create this as a standalone package to use in other projects if I end up liking it.
Switching to urfave/cli#
As I mentioned in the previous post I switched from Cobra to urfave/cli. I haven’t gotten to flags and configs yet but bootstrapping was pretty simple. You can see main.go in the image above and here is the definition for the command. The actual logic is extracted into a function for testing.

Ollama API#
This time I am using the /generate endpoint over /chat for the single query. Since there is no state or chat history it felt more proper.

What was really exciting to me here was finding the Requests library. It cuts out all the boilerplate for doing HTTP requests in Go and makes it more fluid and expressive.
Up Next#
Styling the command output with Bubbletea and maybe Glamour, adding support for piped input, adding images to queries.