goose icon indicating copy to clipboard operation
goose copied to clipboard

Improving the goose CLI command

Open mfridman opened this issue 1 year ago • 4 comments

This issue aims to track improvements to the goose CLI command.

I had a version of the CLI (built with https://github.com/peterbourgon/ff) that I quite enjoyed working with. It was self-documenting, had a bunch of examples, intuitive and (most importantly) easy to compose/maintain.

image

mfridman avatar Dec 12 '23 13:12 mfridman

If no one else is working on this, I can take this up. @mfridman Did I understand correctly that it is desirable to make CLI as on the screenshot?

Albitko avatar Dec 13 '23 15:12 Albitko

I think this is one issue I'll likely take on over the next few months. There's a bit to this issue, and I'd like to avoid leaving a bad experience to contributors dragging out a lengthy review for a major refactor. Some items to think through:

  • We haven't done a major refactor of the CLI in ages and there's a bit of cruft to clean up
  • Use the Provider added in v3.16.0(read more here)
  • Restructure main.go and create a cli package instead of
  • Add context cancellation
  • Evaluate whether a CLI framework would serve us better (maybe not). I have some opinions on CLI frameworks, so it'd be nice to pick something that's ergonomic at the expense of supporting a lot to features
  • Depending on how we re/structure the CLI, I think we can remove the "driver" concept, and solely rely on mapping a DSN to a dialect. There's a nice package for this, https://github.com/xo/dburl
  • Stub out a way to add sub-commands, which allows us to have a hierarchy among commands.
  • Ensure we structure things in a way that we can support outputting JSON, #350

... probably more, but this gives you an idea of the work involved here.

mfridman avatar Dec 16 '23 14:12 mfridman

I've settled on using https://pkg.go.dev/github.com/peterbourgon/ff/v4. It's got just enough knobs to make it useful and I had a fairly good experience with it in the past.

I'd like to minimize breaking changes as much as possible, but there's some quirky behavior in the current goose CLI that'll make 100% backwards compatibility near-impossible. I'll make sure to jot down any changes, although I think most of it will be welcoming.

For example, the following doesn't do what you expect:

goose create --help
2024/03/29 15:02:15 Created new file: 20240329190215_help.go

To make forward progress (without a long-lived branch) and allow folks to experiment with the "new" goose I'll guard this chunk of work with an env variable. In the future, we'll consider promoting this and removing the old code.

GOOSE_CLI=true

I'm also going to make the following 2 functions exportable, which will make it easier for folks to use the CLI code directly in their programs (fix #646) and get all the nice CLI bits.

  1. func Main()
  2. func Run(ctx context.Context, args []string, opts ...RunOptions) error { }

mfridman avatar Mar 29 '24 19:03 mfridman

Here's a first pass at stubbing out the new cli package. https://github.com/pressly/goose/pull/741

I think this is a good base to iterate on, there will likely be changes and shuffles, but it's working and once it's done I've convinced this will be a nice and modern CLI user experience.

mfridman avatar Apr 10 '24 13:04 mfridman