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.

Sending ghost a prompt

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.

exit code definition

This uses a list of constants.

exit codes

You can just wrap the exit code with the error.

exit code wrapping

Then unwrap.

unwrapping exit codes

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.

root command definition

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.

generate definition

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.