litestream icon indicating copy to clipboard operation
litestream copied to clipboard

If -exec is used after the replicate positional arguments it throws a confusing error

Open simonw opened this issue 4 years ago • 3 comments

This works fine:

% litestream replicate \
  -exec "datasette -h 0.0.0.0 -p 8042 notebook.db" \
  notebook.db \
  "s3://my-litestream-bucket/notebook.db"

But if you put the -exec option AFTER the positional arguments (which is usually how I use CLI tools - positional arguments first, options second) you instead get a confusing error message:

% litestream replicate \
  notebook.db \
  "s3://my-litestream-bucket/notebook.db" \
  -exec "datasette -h 0.0.0.0 -p 8042 notebook.db"
litestream v0.3.6
replica url scheme required: -exec

I'd like it if -exec worked after the other arguments, but an alternative fix would be to improve that error message, maybe to:

-exec should be positioned before DB_PATH and REPLICA_URL

simonw avatar Nov 06 '21 00:11 simonw

I just spotted that litestream replicate --help does provide additional clues here:

% litestream replicate --help
The replicate command starts a server to monitor & replicate databases. 
You can specify your database & replicas in a configuration file or you can
replicate a single database file by specifying its path and its replicas in the
command line arguments.

Usage:

	litestream replicate [arguments]

	litestream replicate [arguments] DB_PATH REPLICA_URL [REPLICA_URL...]

simonw avatar Nov 06 '21 00:11 simonw

Thanks for reporting the issue, @simonw. I'm surprised to see that Go's built-in flag package doesn't handle flags after the positional args (https://play.golang.org/p/uWQiOrWIK18). I always assumed it did.

I don't necessarily want to add in a third party dependency like cobra just to add support for this but I can fix up the error message so it's more clear. I could potentially rewrite the args list to move flags to the beginning but that seems like it could have edge cases.

benbjohnson avatar Nov 07 '21 15:11 benbjohnson

Want to +1, had the same issue and found the solution here.

alexpetros avatar Sep 07 '23 22:09 alexpetros